So my code on replit is working as expected but freecodecamp is failing me for this challenge.
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Challenge: URL Shortener Microservice
Link to the challenge:
Instead of doing this:
const REPLACE_REGEX = /^https?:\/\//i
const url2 = url.replace(REPLACE_REGEX, '');
you should do this:
const url2 = new URL(url).hostname;
Thank you so much, brother. It did worked.
For clarification I have this one question. The above regex although does the same why wont it work.
Not quite. The regex only removes protocol (https), but leaves query (stuff that goes at the end after
?). And if you check the docs for dns, you’ll see that it requires hostname as the first argument.