I tried all the different tests and got the right results, but they’re still not passing, except for the last one
My code so far
function convertHTML(str) {
let result=str+''
const regex=/[&<>"']/
for(let i=0;i<result.length;i++){
if(regex.test(result.charAt(i))){
switch(result.charAt(i)){
case '&':
result=result.replace("&","&")
i+=5
break;
case '<':
result=result.replace("<","<")
i+=4
break;
case '>':
result=result.replace(">",">")
i+=4
break;
case '"':
result=result.replace('"',""")
i+=6
break;
case "'":
result=result.replace("'","'")
i+=6
break;
}
}
}
console.log(result)
console.log(result==="Stuff in "quotation marks"")
return result
}
convertHTML('Stuff in "quotation marks"');
My browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities/