actually i begun with building a background color changer app but i wanted to make it a little fun with adding buttons of the possible background colors to challenge the user but i got stuck in the function of checking the answer here s
the html code
<html>
<head>
<title>
document
</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="guess">
<h1> guess the color of the next background color </h1> <br>
<button id="yb" value="yellow" >yellow</button>
<button id="rb" value="red" >red</button>
<button id="wb" value="white" >white</button>
<button id="ob" value="orange">orange</button>
<button id="bb" value="blue">blue</button>
<button id="pb" value="pink">pink</button>
<button id="gb" value="green">green</button>
</div>
<!--<button class="colorBtn" type="button">
click here to change color
</button>
-->
<script src="script.js"></script>
</body>
</html>
and the js code
const colors = ["yellow","red" ,"green" ,"blue" ,"white","pink","orange"];
yb.addEventListener('click',changeColor);
rb.addEventListener('click',changeColor);
wb.addEventListener('click',changeColor);
ob.addEventListener('click',changeColor);
bb.addEventListener('click',changeColor);
pb.addEventListener('click',changeColor);
gb.addEventListener('click',changeColor);
function changeColor(){
let random = Math.floor(Math.random()*colors.length)
bodyBcg.style.backgroundColor=colors[random];
}
const checkAnswer=()=>{
var innerHTML=""
if (yb.value=="yellow")
{
innerHTML=`
<div>
<h1> You got it </h1>
</div>
`
}
else
{innerHTML=`
<div>
<h1> next Time!!!! </h1>
</div>
`}
}
actually the event Listener don 't accept two parameters so i don t know if my beginning of checkAnswer logic is ok and i didn t know where to call the function i m thinking of asynchronous functions ,the truth i understand those type of functions but still not familiar with using it i mean writing it from scratch