Convert HTML Entities < > not working

Tell us what’s happening:
Why it’s not passing following test cases

  • convertHTML(“Sixty > twelve”)
  • convertHTML(“Hamburgers < Pizza < Tacos”)
  • convertHTML("<>")should return&​lt;&​gt;` .

Your code so far


function convertHTML(str) {
  // &colon;&rpar;
  var regex = /\W|_/g;
  for(let i=0;i<str.length;i++){
    if(str[i].match(regex)){
    
      switch(str[i]){
        case '&': str = str.replace('&','&amp;'); break;
        case '<': str = str.replace('<','&​lt;'); break;
        case '>': str = str.replace('>','&​gt;'); break;
        case '\"': str = str.replace('"','&quot;'); break;
        case '\'': str = str.replace('\'','&apos;'); break;
      }

    }
  }
  
  return str;
}

convertHTML("Dolce & Gabbana");

Your browser information:

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

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

This is bizarre but I saw it before.

Your ampersand used in &lt; and &gt; have a zero-width-space character in front of them. Put your cursor after the & (careful to not put it after the zero-width-space) and then delete the character in front of it. This only happened in the &lt; and &gt;, not sure why, maybe because of your keyboard configuration?

If you want to see it, put your cursor before the & in the &gt;, press shift and the arrow to the right slowly, you’ll see there’s one character between the & and the g.

perfect. Thanks @ghukahr

BUT the big question is WHY there is space even though it is not showing up? I feel like it is copy-paste issue

Yes, it’s a copy-paste issue — it could be that the example code on the left side has been pasted across?