Problem with Quotation Marks: Convert HTML Entities

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

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.

1 Like