Tell us what’s happening:
I’m only failing test 8, which is:
- When the button element is clicked, and it contains the class filled, you should remove the class filled from the button element and change the innerHTML of the button element to
.
I can see when I click the button, my background color is removed but the heart is still filled. I thought it was because I used else, so I removed that and add another if statement, but that just made my first if statement not work. I’m kinda at a loss here ![]()
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 class="item-list">
<li><button class="favorite-icon">♡</button></li>
<li><button class="favorite-icon">♡</button></li>
<li><button class="favorite-icon">♡</button></li>
</ul>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
.filled {
background-color: blue;
}
/* file: script.js */
const heartBtn = document.querySelectorAll(".favorite-icon");
function handleBtnClick(btn) {
btn.classList.toggle("filled");
if (btn.innerHTML = "♡") {
btn.innerHTML = "❤";
} else {
btn.innerHTML = "♡";
}
}
heartBtn.forEach(button => button.addEventListener("click", () => {
handleBtnClick(button)
}));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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