Convert HTML Entities - Tests seem like they should pass

Tell us what’s happening:

My code passes all the tests except the “Schindler’s List” and ‘Stuff in “quotation marks”’ tests. What’s especially confusing me is that when I check the output against the asserted output, it matches, but the test is still failing.

Your code so far


function convertHTML(str) {
  // :)
  let chars = [/&/g, /</g, />/g, /\"/g, /\'/g];
  let replacements = ['&amp;', '&lt;', '&gt;', '​&quot;', '&​apos;'];
  for(let i = 0; i < 5; i++) {
    str = str.replace(chars[i], replacements[i]);
  }
  console.log(str);
  return str;
}

convertHTML("Dolce & Gabbana");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities

This sounds weird bro, but as I checked your array ['&amp;', '&lt;', '&gt;', '&quot;', '&​apos;'];, it seems last two elements '&quot;' and '&​apos;' are unicode, while challenge expected ascii.
So the results will have mixed value and fails the tests.

the fix is easy, simply remove the last two elements mentioned above, and type(manually type it, no copy/paste) and try it.

Got around 30min to figure it out bro, you own me a coffee and a beer.

This line

could be better as
for(let i = 0; i < chars.length; i++)

keep goin on great work dude, happy programming.

1 Like

Ohhhh my god. Thank you!!