Week 9 - Task 2b
Make a random "pixel" black
Lets add some stuff to 2a
Javascript
1. In the for-loop from task 2a, when making the tag, now add an id that is uniqe. You will use this uniqe id to find the box and color it black.
Hint: Use the index as part of the id string and read this short guide on how to include variables in a string
2. Generate a random number between 0 and the number of "pixes" you have (X). Use this random number to find (by id) the corresponding "pixel".
Hint:
Use Math.random()
(MDN)
and Math.floor()
(MDN)
3. Color the pixel black by adding a class called "black"
Hint:
Use $element.classList.add('class-name')
to add a class to an element (MDN)
CSS
Create a CSS class called "black" and add the property to this that sets the background color black
Every time you reload the page a different "pixel" should become black
Example of how it might look like