Well I have been able to solve exercise 1 and 2, exercise 2 I have used the event.key but it is not clear to me if that is the correct procedure or how I should have done it and what is used and in what cases, it has really cost me to get there to that. On the other hand, exercise 3 has been impossible for me, I have modified the code so many times that I no longer know how it was, or if it was on the right track.
But the biggest problem of all that is that I don’t know how to get the color of the data-color of each of the buttons so that it gives me as a result in the line
buttonBar.style.backgroundColor = ‘’;
As long as what I did is well planned. And if not, how should it be? it really made my head ache XD.
you doing great well done just a little note here:
in your first take you used return while not need at first cause you just want to set the text to another value and also btn.textContent='Machine is on' does not return value it assignment statement so it set whatever come from the right side of the = sign to the variable on the left side
for task 2 you used the event object so it would be better to make the function has it in it’s paramter list so it be like that wasd(event)
if you used the same way i mentioned in step 2 then you would see many option you can get from the event check this https://developer.mozilla.org/en-US/docs/Web/API/Event
when you set the event on the parent then you do not know what the source that trigger that event did the user clicked on which button or even if he click on any empty area so you want to know the source of the event then you check it’s textcontent and based on that you set the color
hope that give you some idea on how to solve it
by the way if you used an ide like webstorm or Visual Studio Code it would help you alot
no we need those light
let us take it step by step
let color = event.target.textContent; now what is the object that trigger it is it button or the user click on empty space or what
so we ue event.target then we want to know what it's textContent is it red yellow or what so we use event.target.textContent
if(color==="Red"){ now if it red
buttonBar.style.backgroundColor = "red" ; we set the background as you did
}
}
just complete the if else for the other cases and you done