Small Error in Convert HTML Entities Challenge

Tell us what’s happening:

Hi, so I have been stuck on this problem and it seems I am not passing any of the tests except for the last one. However, upon doing a console log for each one, the code seems to work.

After checking the answer, my code looks very similar (I used apostrophes instead of quotation marks for the replacing the apostrophes). The weird thing is that the answer code passes and mine does not. Am I missing something silly that is causing my code to fail the tests? Thanks!

Your code so far

function convertHTML(str) {
  // :)

str = str.replace(/&/g,'&​amp;').replace(/</g,'&​lt;').replace(/>/g,'&​gt;').replace(/"/g,'&​quot;').replace(/'/g,'&​apos;');

// answer code
// str = str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,"&apos;");

return str;


//convertHTML("Dolce & Gabbana");
//convertHTML("Schindler's List");
//convertHTML('Stuff in "quotation marks"');
//convertHTML("Sixty > twelve");
convertHTML("Hamburgers < Pizza < Tacos"); 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:

The problem isn’t the apostrophes. Use them in your code instead of replacing it with the answer and you’ll see it still won’t work. The real issue is your character encoding with & vs &. The one in the answer is a normal UTF-8 character, while yours is a Zero-width space.

If you verify both characters by converting them to Hexidecimal Character Codes, you’ll see that the one in the answer returns 0x26, while yours returns 0x26, 0x200b. The latter being the Zero-width space.

Ah I see (I never would have thought of that haha).

How do I get a hold of the normal UTF-8 version? Is it something I look/convert and then copy and paste?

You’ll have to look at your keyboard settings. They’re probably not set to US international, but some local language instead. I honestly never encountered this issue myself, so it’s just an educated guess. If your keyboard is entering a character that’s somehow different than standard UTF-8, that’d be the first place to look. Another place to check might be some browser setting. But as I said: I’m just guessing here.

1 Like

If you’re using an Apple mobile device, you’ll need to turn off smart punctuation.

1 Like

That makes a lot of sense. I do use an international keyboard occasionally, so perhaps that was on or something.

Thanks again! It feels so much better to know what was going on!