Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an object.
Passing an array instead of an object.
✗ Incorrect
The URLSearchParams constructor accepts an object with key-value pairs to create query parameters.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
set which replaces existing values.Using
add or push which do not exist.✗ Incorrect
The append method adds a new key-value pair to the URLSearchParams object.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
getAll which returns an array.Using non-existent methods like
fetch or find.✗ Incorrect
The get method returns the first value associated with the given key.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
get to check existence which returns a value or null.Using
remove which does not exist.✗ Incorrect
The has method checks if a key exists, and delete removes it.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
set instead of append when adding a parameter.Forgetting to convert to string with
toString().✗ Incorrect
We create params from an object, append a new parameter, then convert to a string with toString().