Great work @anh-vumartell! the codepen shows that it works! Getting code to run is not easy.
Now to improve your code you can try to refactor it. Can we write it with less code to carry out the same action?
To do this let me point you to some articles on MDN and give some idea of what I mean.
Point 1
Lets refer back to the MDN Introduction to Events section. here you see this bit of code on the “Event Objects” section.
function bgChange(e) {
const rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
e.target.style.backgroundColor = rndCol;
console.log(e);
}
btn.addEventListener('click', bgChange);
you can see that there is a parameter ‘e’ within the bgChange function. This would allow the browser to specify what element has been clicked on. This is very powerful. It means that your event listener could carry what element was clicked on to your function and you can carry out the changes bases on the attributes of the clicked button. I would recommend that you read this section again. Can you apply the same logic to your code to reduce the number of lines that you need? a hint is to look at the Div under which all the buttons are children
Point 2
Each of the buttons carries a data attribute. Can you use this to identify the element that was targeted?
Point 3
I tend to use the console.log() function to see what is being generated from my code. I also use an IDE (visual studio code is amazing btw) and carry out my work locally. This might help you more as you get stronger as you learn coding.
Let me know if you have any other questions. Keep learning and asking questions as you have done.