I’m trying to understand the error TypeError: Cannot assign to read only property ‘6’ of string ‘Dolce & Gabbana’. when I have str[i] replacing a string value. When I have an array I don’t have that error. Why does it happen when I try to replace a character value?
**Your code so far**
function convertHTML(str) {
//&=&
//<=<
//>=>
//'""'=no quotes or " "
//'='
for (let i = 0; i < str.length; i++) {
if (str[i] === "&") {
str[i] = "&";
} else if (str[i] === "<") {
str[i] = "<";
} else if (str[i] === ">") {
str[i] = ">";
} else if (str[i] === '"') {
str[i] = """;
} else if (str[i] === "'") {
str[i] = "'";
}
}
return str;
}
console.log(convertHTML("Dolce & Gabbana"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
.
Challenge: Convert HTML Entities
Link to the challenge: