Sid13
1
hello,
when i test my code in browser ,i get the correct result but freecodecamp console don’t validate my code
any help please
thank you
function convertHTML(str) {
const entities={
'&':"&",
'<':"<",
'>':">",
'"':'"',
"'":'''
}
for(key in entities){
regex=new RegExp(key,'g')
while(match=regex.exec(str)){
str=str.replace(key,entities[key])
}
}
return str;
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Convert HTML Entities
Link to the challenge:
try to use proper keyword to declare this
Sid13
3
hi , thank you for your reply, i added the keyword let but still can’t validate my code
function convertHTML(str) {
const entities={
'&':"&",
'<':"<",
'>':">",
'"':'"',
"'":'''
}
for(key in entities){
let regex=new RegExp(key,'g')
while(match=regex.exec(str)){
str=str.replace(key,entities[key])
}
}
return str;
}
log out str before returning like below. That will help to debug it.
function convertHTML(str) {
const entities={
'&':"&",
'<':"<",
'>':">",
'"':'"',
"'":'''
}
for(let key in entities){
console.log(key)
let regex=new RegExp(key,'g')
while(match=regex.exec(str)){
str=str.replace(key,entities[key])
}
}
console.log(str)
return str;
}
and also:
in FCC console, add function call for your code
function convertHTML(str) {
const entities={
'&':"&",
'<':"<",
'>':">",
'"':'"',
"'":'''
}
for(key in entities){
let regex=new RegExp(key,'g')
while(match=regex.exec(str)){
str=str.replace(key,entities[key])
}
}
console.log('str before returning', str)
return str;
}
convertHTML("Dolce & Gabbana")
You will see an error in the console.
system
Closed
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.