0
0
Node.jsframework~10 mins

Encoding and decoding URLs 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 encode a URL component using Node.js built-in function.

Node.js
const encoded = encodeURIComponent([1]);
Drag options to blanks, or click blank then click option'
Acomponent
Burl
CdecodeURIComponent
DencodeURI
Attempts:
3 left
💡 Hint
Common Mistakes
Using encodeURI instead of encodeURIComponent inside the parentheses
Passing decodeURIComponent instead of a string variable
2fill in blank
medium

Complete the code to decode an encoded URL component string.

Node.js
const decoded = [1](encoded);
Drag options to blanks, or click blank then click option'
AdecodeURI
BencodeURI
CencodeURIComponent
DdecodeURIComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Using encodeURI or encodeURIComponent instead of decode functions
Using decodeURI which decodes a full URI, not just a component
3fill in blank
hard

Fix the error in this code that tries to encode a full URL string.

Node.js
const safeUrl = [1](url);
Drag options to blanks, or click blank then click option'
AencodeURIComponent
BdecodeURIComponent
CencodeURI
DdecodeURI
Attempts:
3 left
💡 Hint
Common Mistakes
Using encodeURIComponent on a full URL causing slashes to be encoded
Using decode functions instead of encode
4fill in blank
hard

Fill both blanks to encode a query parameter key and value safely.

Node.js
const query = [1](key) + '=' + [2](value);
Drag options to blanks, or click blank then click option'
AencodeURIComponent
BdecodeURIComponent
CencodeURI
DdecodeURI
Attempts:
3 left
💡 Hint
Common Mistakes
Using encodeURI which does not encode all special characters in query parameters
Mixing encode and decode functions
5fill in blank
hard

Fill all three blanks to decode a full URL, extract a query string, and decode a parameter value.

Node.js
const decodedUrl = [1](url);
const queryString = decodedUrl.split('?')[[2]];
const paramValue = [3](queryString.split('=')[1]);
Drag options to blanks, or click blank then click option'
AdecodeURI
B1
CdecodeURIComponent
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using decodeURIComponent on the full URL instead of decodeURI
Using wrong index when splitting query string
Not decoding the parameter value