Tell us what’s happening:
The code below actually returns the desired result (tested in visual studio code)
But the following goals wont pass (despite of them being returned correctly)
convertHTML("Dolce & Gabbana") should return Dolce & Gabbana
convertHTML("Hamburgers < Pizza < Tacos") should return Hamburgers < Pizza < Tacos
convertHTML("<>")` should return `<>
The rest of them actually pass correctly.
Im not sure this is the most efficent way to code the task, but it returns what the task asks for
Your code so far
function convertHTML(str) {
var splitted = str.split("");
console.log(splitted);
for(let i = 0; i<splitted.length;i++){
if(splitted[i] == '&'){
splitted.splice(i, 1, '&');
}else if(splitted[i] == '<'){
splitted.splice(i, 1, '<');
}else if(splitted[i] == '>'){
splitted.splice(i, 1, '>');
}else if(splitted[i] == '"'){
splitted.splice(i, 1, '"');
}else if(splitted[i] == "'"){
splitted.splice(i, 1, ''');
}
}
console.log(splitted.join(""));
return splitted.join("");
}
convertHTML("Dolce & Gabbana");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities