Problem with Quotation Marks: Convert HTML Entities

Problem with Quotation Marks: Convert HTML Entities
0

#1

Tell us what’s happening:
My code appears to work for all test cases in Chrome’s console, but it won’t pass the test cases with quotation marks or apostrophes in the FCC console.

For example, when I use the Chrome console, convertHTML('Stuff in "quotation marks"') returns Stuff in &​quot;quotation marks&​quot;

However, when I run the challenge through the FCC console, the same test case gives me an error: transformers.js:85 SyntaxError: unknown: Unexpected token, expected , (21:24)…

Can someone help me figure out what’s going on?

Your code so far


function convertHTML(str) {
  // :)
  var arr = str.split("");
  var conv = {
    "&":"&",
    "<":"&lt;",
    ">":"&gt;",
    "'":"&​apos;",
    '"':"&​quot;"
  };

  for (let i = 0; i < arr.length; i++){
    if(conv[arr[i]]){
      arr[i]=conv[arr[i]];
    }
  }
return arr.join("");

}

convertHTML("Dolce & Gabbana");

Your browser information:

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

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


#2

Retype the those two strings (the replacement values for the apostrophe and the double quote), because you have some extra hidden characters in those two strings which are throwing off the tests.


#3

You most likely copied and pasted. If you did, you most likely have some hidden chars that don’t show up. Don’t believe me? try back spacing on your converted texts in var conv. You’ll need to type &amp and the others manually.