0
0
Node.jsframework~10 mins

URLSearchParams for query strings in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new URLSearchParams object.

Node.js
const params = new URLSearchParams([1]);
Drag options to blanks, or click blank then click option'
A{ name: 'John', age: '30' }
Bnull
C['name', 'John']
D'name=John&age=30'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an object.
Passing an array instead of an object.
2fill in blank
medium

Complete the code to add a new parameter 'city' with value 'Paris'.

Node.js
params.[1]('city', 'Paris');
Drag options to blanks, or click blank then click option'
Aappend
Badd
Cset
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using set which replaces existing values.
Using add or push which do not exist.
3fill in blank
hard

Fix the error in the code to get the value of 'name'.

Node.js
const name = params.[1]('name');
Drag options to blanks, or click blank then click option'
AgetAll
Bfind
Cfetch
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using getAll which returns an array.
Using non-existent methods like fetch or find.
4fill in blank
hard

Fill both blanks to check if 'age' exists and then delete it.

Node.js
if (params.[1]('age')) {
  params.[2]('age');
}
Drag options to blanks, or click blank then click option'
Ahas
Bget
Cdelete
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using get to check existence which returns a value or null.
Using remove which does not exist.
5fill in blank
hard

Fill all three blanks to create a query string, append a parameter, and convert to string.

Node.js
const params = new URLSearchParams([1]);
params.[2]('lang', 'en');
const queryString = params.[3]();
Drag options to blanks, or click blank then click option'
A{ page: '1', sort: 'asc' }
Bappend
CtoString
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using set instead of append when adding a parameter.
Forgetting to convert to string with toString().