I have a problem I'm struggling to solve. I've made 3 boxes in html/css and have an eventListener so when one box is clicked it changes to red. What I want to do is make all boxes green once all boxes have been colored red. Here was my attempt:
var buttonOne = document.querySelector(".one");
var buttonTwo = document.querySelector(".two");
var buttonThree = document.querySelector(".three");
function makeBoxRed(event) {
var boxClicked = event.target;
boxClicked.style.backgroundColor = "red";
}
var boxes = document.querySelector(".boxes");
boxes.addEventListener("click", makeBoxRed);
if ((boxes.style.backgroundColor = "red")) {
boxes.style.backgroundColor = "green";
}
div {
border: 1px solid black;
height: 100px;
width: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<section class="boxes">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</section>
</body>
</html>