Last test not passing

I used this code to solve this challenge and it passes all the tests except the last. This is probably a bug, since I logged the return value from the console and “abc” (quotes included) is correctly logged.

Please correct me if I am doing something wrong. Thanks.

Your code so far


function convertHTML(str) {
 let newStr='';
 for(let s of str){
   switch(s){
     case '&':
     newStr+='&';
     break;
     case '<':
     newStr+='&lt;';
     break;
     case '>':
     newStr+='&gt;';
     break;
     case '"':
     newStr+='&quot;';
     break;
     case '\'':
     newStr+='&apos;';
     break;
     default:
     newStr+=s;
     break;
   }
 }
return '"'+newStr+'"';

}

convertHTML("abc");

Your browser information:

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

Challenge: Convert HTML Entities

Link to the challenge:

why are you adding quotes inside your string?

1 Like

Because for the tests to pass we’re supposed to return the string with quotes.

UPDATE: Sorry I just removed the quotes and it worked. I was somehow under the impression that the string to be returned had to be in quotes for the challenge to pass the test cases.

1 Like