Tell us what’s happening:
The entitys after i click the button doesn’t show as an emoji instead, it shows as text
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Favorite Icon Toggler</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<ul>
<li class="item-list">120 gm paper<button type="botton" class="favorite-icon">♡</button></li>
<li class="item-list">130 gm paper<button type="botton" class="favorite-icon">♡</button></li>
<li class="item-list">140 gm paper<button type="botton" class="favorite-icon">♡</button></li>
</ul>
<script src="./script.js"></script>
</body>
</html>
/* file: styles.css */
.filled{
//background-color:red;
}
/* file: script.js */
let bottomsArray=document.querySelectorAll(".favorite-icon")
console.log(bottomsArray)
bottomsArray.forEach((curr)=>{curr.addEventListener("click",()=>{curr.classList.toggle("filled");
curr.textContent=curr.textContent =="♡"?"❤":"♡";
})})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Challenge Information:
Build a Favorite Icon Toggler - Build a Favorite Icon Toggler
https://www.freecodecamp.org/learn/full-stack-developer/lab-favorite-icon-toggler/build-a-favorite-icon-toggler
example:
the colum dosent change anything, the entity codes are directly copied from the exercise
ILM
September 17, 2025, 5:45pm
4
please post your updated code
dhess
September 17, 2025, 8:09pm
5
There are issues with your button event listener:
To see the first issue, console.log() your ternary condition for both html entities.
Can you think of an alternative condition you could use?
And this stackoverflow post might help you resolve the other issue.
javascript:
let bottomsArray=document.querySelectorAll(".favorite-icon")
bottomsArray.forEach((curr)=>{curr.addEventListener("click",()=>{curr.classList.toggle("filled");
curr.textContent=curr.textContent =="♡"?"❤":"♡";
})})
css
.filled{
//background-color:red;
}
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Favorite Icon Toggler</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<ul>
<li class="item-list">120 gm paper<button type="botton" class="favorite-icon">♡</button></li>
<li class="item-list">130 gm paper<button type="botton" class="favorite-icon">♡</button></li>
<li class="item-list">140 gm paper<button type="botton" class="favorite-icon">♡</button></li>
</ul>
<script src="./script.js"></script>
</body>
</html>
dhess
September 17, 2025, 11:08pm
9
Log this:
console.log(curr.textContent == "♡")
console.log(curr.textContent == "❤")
One of them should be true, right?
intresting fact is the 1st time i clicked the button is displays false false
dhess
September 17, 2025, 11:58pm
13
You shouldn’t be using AI in this forum…it’s actually against the rules. And, as you pointed out, when you click the button repeatedly, you do get true/false values. It’s just the first click that produces the false/false values.
i didnt know im going to delete it
dhess:
it’s actually against the rules. And, as you pointed out, when you click the button repeatedly, you do get true/false values. It’s just the first click that produces the false/false values.
im stuck on this exercise
dhess
September 18, 2025, 12:04am
17
You’ll figure it out. HINT: Look at all of your code…there may be discrepancies.
And don’t forget about that stackoverflow post.
i changed to insert as innerhtml so it would covert the html entities to emoji heart
my js:
let bottomsArray=document.querySelectorAll(".favorite-icon")
bottomsArray.forEach((curr)=>{curr.addEventListener("click",()=>{curr.classList.toggle("filled");
//console.log(curr.textContent =="♡"?"❤":"♡")
console.log(curr.textContent )
curr.innerHTML=curr.textContent =="♡"?"❤":"♡";
})})
my code is literaly working
My tests werent passing is because FreeCodeCamp checks for the class logic explicitly, not just the heart toggle. it requiers me to not use toggle but an condition logic with contains method