0
0
Node.jsframework~10 mins

URL class for parsing 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 from a string.

Node.js
const myUrl = new URL([1]);
Drag options to blanks, or click blank then click option'
AURL('https://example.com')
Bnew URL('https://example.com')
Chttps://example.com
D'https://example.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the URL string.
Passing the URL constructor itself as an argument.
2fill in blank
medium

Complete the code to get the hostname from a URL object.

Node.js
const hostname = myUrl.[1];
Drag options to blanks, or click blank then click option'
Aorigin
Bhostname
Chref
Dhost
Attempts:
3 left
💡 Hint
Common Mistakes
Using host which includes port number.
Using href which is the full URL string.
3fill in blank
hard

Fix the error in accessing the pathname of a URL object.

Node.js
const path = myUrl.[1];
Drag options to blanks, or click blank then click option'
Apathname
BgetPathname
Cpath
DgetPath
Attempts:
3 left
💡 Hint
Common Mistakes
Calling pathname as a function with parentheses.
Using non-existent methods like getPath.
4fill in blank
hard

Fill both blanks to create a URL object with a base URL.

Node.js
const myUrl = new URL([1], [2]);
Drag options to blanks, or click blank then click option'
A'/page.html'
B'https://example.com'
C'page.html'
D'http://localhost'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a full URL as the first argument and base URL as second.
Omitting the base URL when using a relative path.
5fill in blank
hard

Fill all three blanks to extract the protocol, hostname, and port from a URL object.

Node.js
const protocol = myUrl.[1];
const hostname = myUrl.[2];
const port = myUrl.[3];
Drag options to blanks, or click blank then click option'
Aprotocol
Bhostname
Cport
Dhost
Attempts:
3 left
💡 Hint
Common Mistakes
Using host instead of hostname and port separately.
Forgetting the colon ':' in protocol value (it is included automatically).