Tell us what’s happening:
my code keeps on failing tests 5 and 6 (“Your individual list item should contain a button element with the class favorite-icon.” and
“Initially, the button elements should contain the code to represent an empty heart.”). What am I doing wrong?
My code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<ul class = "item-list">
<button class="favorite-icon" type="btn"></button) class="item-list">
<li>a<span class="favorite-icon">♡</span><button class="favorite-icon" type="btn"></button)</li>
<li>b<span class="favorite-icon">♡</span><button class="favorite-icon" type="btn"></button)</li>
<li>c<span class="favorite-icon">♡</span></li>
</ul>
<script src="script.js"></script>
/* file: styles.css */
.filled {
color: rgb(1, 147, 59);
}
/* file: script.js */
const spans = document.querySelectorAll(".favorite-icon");
spans.forEach((span) => {
span.addEventListener("click", () => {
if (span.classList.contains("filled")) {
span.classList.remove("filled");
span.innerHTML = "♡";
} else {
span.classList.add("filled");
span.innerHTML = "❤";
}
});
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Challenge Information:
Build a Favorite Icon Toggler - Build a Favorite Icon Toggler