Tell us what’s happening:
- Each of your name property values should match one of the values you provided for the li elements. Make sure these values are all in lowercase.
- When a user clicks the #theme-switcher-button and selects a theme, a message related to the selected theme from the themes array should be displayed in the aria-live=“polite” element. i can’t pass this two pls help me
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 id="theme-dark" role="menuitem" >Dark</li>
<li id="theme-green" role="menuitem">Green</li>
<li id="theme-blue" role="menuitem">Blue</li>
<li id="theme-red" role="menuitem">Red</li>
</ul>
<h2 id="status" aria-live="polite"></h2>
<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;
}
#status {
text-align: center;
min-height: 20px;
}
/* file: script.js */
const themes = [{name: "theme-dark",message:"the god of light"}
,{name: "theme-green",message:"super tiger of hidden leaf"}
,{name:"theme-blue",message:"blue sky no limit"}
,{name:"theme-red",message:"super red red red red uzumaki"}]
const btn = document.getElementById("theme-switcher-button")
const dropList = document.getElementById("theme-dropdown")
btn.addEventListener('click',()=>{
dropList.hidden = !dropList.hidden
btn.setAttribute("aria-expanded",dropList.hidden?"false":"true")
statusOut.textContent = ""
})
const statusOut = document.getElementById("status")
console.log(themes[1].name.slice(themes[1].name.indexOf("-")+1))
const listChoice = document.querySelectorAll("[role=menuitem]")
listChoice.forEach(theme=>{
theme.addEventListener("click",()=>{
document.body.classList.remove("theme-dark","theme-green","theme-blue","theme-red")
let id = theme.id
let getTheme = themes.find(elem=>elem.name===id)
if(getTheme){
statusOut.textContent=getTheme.message
document.body.classList.add(getTheme.name)
}
dropList.hidden = !dropList.hidden
btn.setAttribute("aria-expanded",dropList.hidden?"false":"true")
})
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build a Theme Switcher - Build a Theme Switcher
