Understanding Javascript conditions and loops
-
Fork this repo.
-
Only code inside the file named
script.js
. No editing any other files. -
Write a
for
loop to add a click event listener on all divs with classbox
. -
When the user clicks any box, change that box's background color to one of the following colors.
-
If number of boxes on the page is between 201 and 300, inclusive, change the background color of the box to 'yellow'.
-
If number of boxes on the page is between 301 and 400, inclusive, change the background color of the box to 'green'.
-
If number of boxes on the page is between 401 and 500, inclusive, change the background color of the box to 'purple'.
-
If number of boxes on the page is between 501 and 600, inclusive, change the background color of the box to 'orange'.
-
If number of boxes on the page is between 601 and 700, inclusive, change the background color of the box to 'pink'.
-
If number of boxes on the page is between 701 and 800, inclusive, change the background color of the box to 'black'.
-
If number of boxes on the page is between 801 and 900, inclusive, change the background color of the box to 'brown'.
-
Otherwise, change the background color of the box to 'blue'.
-
- In the click event function, change that box's class to
clicked
. If it's already the class ofclicked
, change it back tobox
. Basically, if a box is clicked, it should toggle between the css class ofbox
andclicked
.