Tell us what’s happening:
Hey, could I have some help? What’s wrong in my code?
It says in repl.it when I run it that it is:
RangeError: Potential infinite loop. You can disable this from settings.
at convertHTML:15:107
at eval:26:1
And when I run it in Chrome console it stops working (the actual FCC website), so I suspect an infinite loop, but I don’t see where it is??
Your code so far
function convertHTML(str) {
let entities = { //Object created for later use
'&':'&',
'<':'<',
'>':'>',
'"':'"',
'\'':'''
}
str=str.split(""); //str coming into meta-functionis converted to array
let keyz=Object.keys(entities); //Assigning every key in the object "entities" to the array "keyz"
let valuez=Object.values(entities); //Assigning every value in the object "entities" to the array "valuez"
for (let i=0; i<str.length; i++) { //Looping over str's elements
for(let j=0;j<keyz.length;i++){ //Looping over every key in entities
if (keyz[j]===str[i]) { //If current key of entities that is being looped over, equals the element of string which is currently being looped over
str[i]=valuez[j]; //Then make that element of string equal to property of key currently looped over
} //I thought this should work because keys and properties will be at same index of their separate arrays
}
}
console.log(str); //Test
str.join("");
return str;
}
convertHTML("Dolce & Gabbana");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities/