Tell us what’s happening:
Hello, my code passes all the tests except one, which is why I find this so strange. It fails on the convertHTML("<>")
should return <>
test, and yet it successfully converts those same characters on the other tests, so I can’t figure out why it fails on this one.
Your code so far
function convertHTML(str) {
let testChar = '&';
console.log('testChar: ' +testChar);
let newChar = '';
let regex = /[&<>"']/g
let finalStr = '';
function convert(obj) {
let converted = '';
switch(obj) {
case '&':
converted = '&';
break;
case '<':
converted = '<';
break;
case '>':
converted = '>';
break;
case '"':
converted = '"';
break;
case "'":
converted = ''';
break;
}
console.log('converted: ' +converted);
return converted;
}
let strArr = str.split('');
console.log(strArr);
for (let i = 0; i < strArr.length; i++) {
if (regex.test(strArr[i])) {
newChar = convert(strArr[i]);
strArr.splice(i,1,newChar);
console.log('splice: ' +strArr);
}
}
finalStr = strArr.join('');
console.log(finalStr);
// :)
return finalStr;
}
convertHTML("<>");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge:
Won’t let me post links with this new account so had to delete the link from the template.