It looks like there are a couple of issues with your code. Here are some suggestions on how to fix them:
Use querySelectorAll to select all the div elements:
javascript
var box = document.querySelectorAll("div");
In your loop, you need to refer to the current element using this:
javascript
for (var i = 0; i < box.length; i++) {
box[i].addEventListener("mouseover", function () {
this.style.backgroundColor = "blue";
});
box[i].addEventListener("mouseout", function () {
this.style.backgroundColor = "pink";
});
}
In the mouseover and mouseout event listeners, you need to refer to the current element using this. Also, you need to set the backgroundColor property of the current element (this), not the box variable.
Putting it all together, your updated code should look like this:
javascript
var box = document.querySelectorAll("div");
for (var i = 0; i < box.length; i++) {
box[i].addEventListener("mouseover", function () {
this.style.backgroundColor = "blue";
});
box[i].addEventListener("mouseout", function () {
this.style.backgroundColor = "pink";
});
}
With these changes, you should be able to hover over and off each div to change its background color.