0
0
Node.jsframework~10 mins

Building URLs programmatically 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 URL object with the base 'https://example.com'.

Node.js
const url = new URL([1]);
Drag options to blanks, or click blank then click option'
A'http://localhost'
B'https://example.com'
C'ftp://fileserver.com'
D'example.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the protocol in the URL string.
Using a relative URL without a base.
2fill in blank
medium

Complete the code to add a query parameter 'search' with value 'books' to the URL.

Node.js
url.searchParams.append([1], 'books');
Drag options to blanks, or click blank then click option'
A'type'
B'query'
C'filter'
D'search'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter key like 'query' or 'filter'.
Forgetting quotes around the key string.
3fill in blank
hard

Fix the error in the code to correctly set the pathname to '/products'.

Node.js
url.[1] = '/products';
Drag options to blanks, or click blank then click option'
Apath
Burl
Cpathname
Dlocation
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'path' instead of 'pathname'.
Trying to set 'url' or 'location' properties.
4fill in blank
hard

Fill both blanks to create a URL with base 'https://api.example.com' and add a query parameter 'page' with value '2'.

Node.js
const url = new URL([1]);
url.searchParams.append([2], '2');
Drag options to blanks, or click blank then click option'
A'https://api.example.com'
B'page'
C'limit'
D'offset'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong base URL or missing protocol.
Using incorrect query parameter keys like 'limit' or 'offset'.
5fill in blank
hard

Fill all three blanks to create a URL with base 'https://shop.com', set pathname to '/items', and add query parameter 'category' with value 'books'.

Node.js
const url = new URL([1]);
url.[2] = '/items';
url.searchParams.append([3], 'books');
Drag options to blanks, or click blank then click option'
A'https://shop.com'
Bpathname
C'category'
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'path' instead of 'pathname'.
Forgetting quotes around strings.
Using wrong query parameter keys.