I have been trying to code the following exercise on freecodecamp and I am getting the same string as is shown in desired output, but the test fails on the site.
Code:
function convertHTML(str) {
res = "";
for (let i in str) {
if (str[i] == '&') {
res= res.concat("&");
}
else if (str[i] == '<') {
res = res.concat("<");
}
else if (str[i] == '>') {
res = res.concat(">");
}
else if (str[i] == '\"') {
res = res.concat(""");
}
else if (str[i] == "\'") {
res = res.concat("'");
}
else {
res = res.concat(str[i]);
}
}
return res;
}
What could be the source of error