loopy pham-ily house
welcome! the lights in this house are controlled by a for loop-loving landlord.
play around with the dropdown to understand the counter initialization, the looping condition, and
the incrementer expressions.
for (let i =
; i <
;
){ turnOnLight() }
tasks
assuming the first element of the array is top left, figure out what settings to turn on the following lights:
- every light
- every light on the top floor
- every light on the bottom floor
- every other light in the whole house (starting from the first one)
- every other light in the whole house (starting from the second one)
- every light other than the first and last one
questions
reflect on the following questions
- why are the counter initialization values from 0 to 7?
- if you don't know the length of your array, what should you use for your looping condition?
- what happens when the looping condition goes beyond the array length?
- what is another way to write i++ (look at the other dropdowns for the incrementer)?
Back to Projects