Not passing a test on convert html entities challenges

Not passing a test on convert html entities challenges
0

#1

Only first case is running.

code:

function convertHTML(str) {
let astr=str.split("");
let rstr=""+str;
for( let x of astr){
  switch(x){
    case "&":
    rstr=rstr.replace("&","&");
    break;
    case "<":
     rstr=rstr.replace("<","&​lt;");
     break;
      case ">":
     rstr=rstr.replace(">","&​gt;");
     break;
      case '"' :
     rstr=rstr.replace('"'," &​quot;");
     break;
      case "'":
     rstr=rstr.replace("'","&​apos;");
     break;

  }
}
  return rstr;
}

convertHTML("Dolce & Gabbana");

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


Intermediate Algorithm Scripting: Convert HTML Entities (BUG?)
#2

In the future, please create a new post if you have questions about your own code and are not commenting on another user’s thread.

I moved your question to it’s own topic.

My guess is that you copied and pasted the replace values instead of typing them out and accidentally copied some hidden characters in those strings which are throwing the tests off. Try typing out the replacement values and see if you pass the tests.