Tell us what’s happening:
Hello, the test number 21 is that themes array property name should match exactly with li element values and I am really confused why that test doesn’t pass. My whole code works as it is supposed to do, however it also doesn’t recognize test 27, which is to have the messages in the aria-live=“polite” element.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Theme Switcher</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<button id="theme-switcher-button" aria-haspopup="true" aria-expanded="false" aria-controls="theme-dropdown">Switch Theme
</button>
<ul id="theme-dropdown" role="menu" aria-labelledby="theme-switcher-button" hidden >
<li value="theme-light "id="theme-light" role="menu-item">Light</li>
<li id="theme-dark" value="theme-dark" role="menu-item">Dark</li>
</ul>
<p aria-live="polite"></p>
<script src="./script.js"></script>
</body>
</html>
/* file: styles.css */
body {
margin: 0;
font-family: sans-serif;
transition: background 0.3s, color 0.3s;
}
ul {
margin: 0;
padding: 0;
}
li {
list-style-type: none;
cursor: pointer;
margin: 5px 0;
}
li:hover {
color: gray;
}
#status {
text-align: center;
min-height: 20px;
}
.theme-light {
color: white;
background-color: yellow;
}
.theme-dark {
color: lightgreen;
background-color: darkblue;
}
/* file: script.js */
const switcherBtn = document.getElementById("theme-switcher-button");
const themeDrop = document.getElementById("theme-dropdown");
const p = document.querySelector("[aria-live='polite']")
const themes = [
{ name: "theme-light", message: "The brightness is on!" },
{ name: "theme-dark", message: "The darkness is on!" }
];
switcherBtn.addEventListener("click", () => {
themeDrop.hidden = !themeDrop.hidden;
switcherBtn.setAttribute("aria-expanded", themeDrop.hidden ? "false" : "true");
p.innerText = '';
document.body.className = '';
});
themeDrop.querySelectorAll("li").forEach(item => {
item.addEventListener("click", () => {
const id = item.id;
document.body.className = id;
const themeObj = themes.find(t => t.name === id);
p.innerText = themeObj.message;
themeDrop.hidden = true;
switcherBtn.setAttribute("aria-expanded", "false");
});
});
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 Theme Switcher - Build a Theme Switcher
https://www.freecodecamp.org/learn/full-stack-developer/lab-theme-switcher/lab-theme-switcher
