Here's the problem:
Change the 3 divs below (they're not visible) to be 50x50 red squares
<div class="empty"></div>
<div class="empty"></div>
<div class="empty"></div>
Built in class that we are changing to:
<style media="screen">
.red{
width:50px;
height:50px;
background:red;
}
This solution only acts on the first and last div, leaving the middle out:
let boxes = document.getElementsByClassName('empty');
function addThree(boxes) {
for (let i = 0; i < boxes.length; i++) {
boxes[i].className = 'red';
}
}
addThree(boxes);
Solution that does work on all three divs;
let boxes = document.getElementsByClassName('empty');
function addThree(boxes) {
for (let i = 0; i < boxes.length; i++) {
boxes[i].classList.add('red');
}
}
addThree(boxes);
Not really sure what the difference here is, if anyone could give a explanation that would be awesome!