Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the URL string.
Passing the URL constructor itself as an argument.
✗ Incorrect
You need to pass the URL string as a quoted string to the URL constructor.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
host which includes port number.Using
href which is the full URL string.✗ Incorrect
The hostname property gives just the domain name without port.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling
pathname as a function with parentheses.Using non-existent methods like
getPath.✗ Incorrect
The pathname is a property, not a function, so no parentheses are needed.
4fill in blank
hardFill 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'
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.
✗ Incorrect
The first argument is the relative path, the second is the base URL string.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
host instead of hostname and port separately.Forgetting the colon ':' in protocol value (it is included automatically).
✗ Incorrect
Use protocol, hostname, and port properties to get these parts.