Please I need to know why my code didnt pass the last test "abc"

Tell us what’s happening:
Describe your issue in detail here.
My code passed all the tests, except for the “abc” test, and yet returning abc .
string as output.
Your code so far


function convertHTML(str) {
let newStr = str.split('');
 for(let i=0; i<newStr.length; i++){
       switch(newStr[i]){
           case "<":
            newStr.splice(i, 1, "&lt;");
            break;
            case "&":
            newStr.splice(i, 1, "&amp;");
            break;
             case ">":
             newStr.splice(i, 1, "&gt;");
            break;
             case '"':
             newStr.splice(i, 1, "&quot;");
            break;
              case "'":
             newStr.splice(i, 1, "&apos;");
            break;
            default:
             newStr.splice(i,"abc.");
       }
      
 }
  return newStr.join("")+".";
}

console.log(convertHTML("abc"));
  **Your browser information:**

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

Challenge: Convert HTML Entities

Link to the challenge:

Hi @ayobamiwealth !

I am not sure why you added a period here.

But if you get rid of it then it passes.

Also, you don’t need it here

Hope that helps!

1 Like

Yes, thanks it worked. Then please can you explain what’s happening here " newStr.splice(i, 1, "&amp;");", "1" which is the number of items to delete.

In here

The i is the index where you start changing the array.
The 1 as you mentioned is the delete count.
The "&amp;" is what you are adding to the array.

But I don’t know what this part is

That wasn’t in your original code.
Where did you get that?

1 Like

Sorry that was a mistake. Thanks for the explanation

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.