Convert HTML Entities - Weird issues?

I have two solutions here that work perfectly in VScode, but aren’t working here in FCC. Well, they are working but I’m still getting marked as wrong.

Can someone take a look at this and tell me what’s up?


// function convertHTML(str) {
//   // :)
//   const ampReg = /&/g;
//   const leftBrac = /</g;
//   const rightBrac = />]/g;
//   const singleQuot = /'/g;
//   const doubleQuot = /"/g;
//   const newStr = str
//     .replace(ampReg, "&amp;")
//     .replace(leftBrac, "&​lt;")
//     .replace(rightBrac, "&​gt;")
//     .replace(singleQuot, "&​apos;")
//     .replace(doubleQuot, "&​quot;");
//   return newStr;
// }

function convertHTML(str) {
  let arr = str.split("");
  arr.forEach((val, ind) => {
    switch (val) {
      case "&":
        arr[ind] = "&amp;";
        break;
      case "<":
        arr[ind] = "&​lt;";
        break;
      case ">":
        arr[ind] = "&​gt;";
        break;
      case "'":
        arr[ind] = "&​apos;";
        break;
      case '"':
        arr[ind] = "&​quot;";
        break;
    }
  });
  console.log(arr.join(""));
  return arr.join("");
}

convertHTML("Dolce & Gabbana");

Your browser information:

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

You may want to type the html entities instead of copy-pasting them. There are invisible characters in there:

1 Like

That was it.

Weird. Never expected a bunch hidden characters. But, it worked after I fixed that.