Resources
- //INIT: Creating arrays
-
//PROCESS:
for
loops
Saving your work
Use Save as...
to save the empty
template as
"3.07S-MakeARainbow-LastName.html
"
in your Computer Programming 12 directory.
The assignment
Use arrays and for...in
loops to create rainbow.
For example
Behold! The magical power of light!
Or change it up into a series of <span>
s
Behold! The other, very similar power of light!
Or stagger the <span>
s using
style="position: relative; top: ???px;"
Behold! An awesome staircase of light!
Hints
-
Create a
<div>
withid="outputId"
in the body of your code -
Create a button that will trigger
mainProcedure()
- Initialize your rainbow array
-
Create an output function that will insert a result into
outputId
-
Create a process function that uses
for...in
loops to create a list -
Use inline styles to add the background colour:
<li style='background-color: red;'></li>
Note: Using Javascript to create code with inline styles is being seen as increasingly amateurish. It is OK to use inline styles in generated code for the meantime. But ask yourself how you can add a class instead - or even better - how to create an element and then add.style.backgroundColor
to it. -
Create a
mainProcedure
function that will pass the rainbow array to your process function, and then pass the results to your output function -
Reread //PROCESS:
for
loops for more info