Exercise: Using clicks and arrays
Write the code for the function rainbowClick
so that clicking repeatedly on the Z results in changes to the background colour using the colours in the array rainbow
and the classesAn attribute used to refer to a group of elements. in the CSS file.
Note:
Hints:
Use
getAttribute
to determine the current class.
Solution to the exercise
Here is a possible solution to the exercise.
Note:
Hints:
- undefined
1
2
window.onload = startFunction;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
<!DOCTYPE html>
<html lang="en">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
td {
background-color: yellow;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX