Tell us what’s happening:
Test 23 fails, no matter how many times i change the code
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 class='theme-light'>
<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 role='menuitem' id='theme-light'>Light</li>
<li role='menuitem' id='theme-red'>Red</li>
<li role='menuitem' id='theme-blue'>Blue</li>
</ul>
<p id='status' 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;
position: absolute;
background-color: #ffffff;
min-width: 160px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
z-index: 1;
}
li {
width: 100%;
padding: 12px;
color: #000000;
background-color: #ffffff;
cursor: pointer;
}
.theme-blue {background-color:blue}
.theme-red {background-color:red}
li:hover {background-color:grey}
#status {
text-align: center;
min-height: 20px;
}
#theme-switcher-button {
position: relative;
padding: 10px 20px;
border: none;
cursor: pointer;
}
/* file: script.js */
let button = document.getElementById("theme-switcher-button");
let options = document.getElementById('theme-dropdown');
let menuItems = document.querySelectorAll('[role="menuitem"]');
let isHidden = true;
let previousColor = 'theme-light';
let message = document.getElementById('status');
let colorIndex;
let themes =
[
{
name:"light",
message:"me oiyes"
},
{
name:"red",
message:"yeaahh!!"
},
{
name:"blue",
message:"im blue daba dee daba dai"
}
];
button.addEventListener('click',() =>
{
showOrHideMenu();
});
menuItems.forEach(item => item.addEventListener('click',() =>
{
closeMenu();
document.body.classList.replace(previousColor,item.id);
previousColor = item.id;
colorIndex = themes.findIndex(theme => theme.name === item.id.split('-')[1]);
message.textContent = themes[colorIndex].message;
}));
function showOrHideMenu() {
isHidden = !isHidden;
options.hidden = isHidden;
button.setAttribute('aria-expanded',String(!isHidden));
}
function closeMenu() {
isHidden = true;
options.hidden = true;
button.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/141.0.0.0 Safari/537.36 OPR/125.0.0.0
Challenge Information:
Build a Theme Switcher - Build a Theme Switcher