Convert HTML Entities - My problem

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={
    "&":"&​amp;",
    "\"":"",
    "<":"&​lt;",
    ">":"&​gt;",
    "'":"&​apos;",
  }
  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

First thing first, you have invisible characters in there and you are replacing the quote with an empty string

image

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 &quot;.

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

For some reason that characters are hidden in the html in the challenge description - no idea why

My response from another thread:

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 :slight_smile: