Hi, all
I’m trying to figure my solution for the Algorithm Scripting | Convert HTML Entities challenge and since i like using if else to figure solution for this challenge i do it with it but, when i click Run test … It doesn’t work !!!
this is my code :
function convertHTML(str) {
let newstr = str.split('')
for (let i = 0; i < newstr.length; i++) {
if (newstr[i] == '&') {
newstr[i] = '&';
}
else if (newstr[i] == '<') {
newstr[i] = '<';
}
else if (newstr[i] == '>') {
newstr[i] = '>'
}
else if (newstr[i] == '"') {
newstr[i] = '"';
}
else if (newstr[i] == "'") {
newstr[i] = ''';
}
}
newstr = newstr.join('');
return newstr;
}
console.log(convertHTML("Dolce & Gabbana")) // Dolce & Gabbana
Thanks