Tell us what’s happening:
My code console logiing the same expected result but it is not accepted. Can anyone Help by clarifying why it is
Your code so far
function convertHTML(str) {
// :)
var charSet={
"&":"&",
"\"":"",
"<":"<",
">":">",
"'":"'",
}
return str.split("").map(function(element) {
if(charSet[element])
return charSet[element];
else
return element;
}).join("");
}
console.log(convertHTML("Dolce & Gabbana"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities
ilenia
March 17, 2019, 7:41am
2
First thing first, you have invisible characters in there and you are replacing the quote with an empty string
If this was the issue you just need to type them, instead of copy-pasting, and add the missing one
2 Likes
You also have a problem here:
"\"":"",
This will delete all double quotation marks (replace with empty string), whereas you need to replace them with "
.
1 Like
thank you both for your immediate replies
yeah, now I can see the invisible char if I paste this code in JsFiddle editor.
But why it is happening… Is there any reason
ilenia
March 17, 2019, 8:37am
6
For some reason that characters are hidden in the html in the challenge description - no idea why
My response from another thread:
This bug is a little bizarre. I’m guessing you copy/pasted the entities from the test descriptions, which “escape” the entities in a rather unusual way, and as a result, you get this:
'&' === '&' //false
'&'.length //6
'&'.split(''); //["&", "", "a", "m", "p", ";"]
'&'.codePointAt(1).toString(16); //"200b"
That codepoint, U+200B , is a zero-width space . It’s one of a few zero-width characters in Unicode that are very useful for specialized applications but can also poop on your parade when you least expect it.
Delete all those zero-width spaces and your code should pass the test cases with no problems.
It looks like the test descriptions have already been fixed on the master branch of the fCC repo, but the newest version hasn’t been pushed to production yet.
1 Like
Thank you so much for your reply. Useful