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:
  1. every light
  2. every light on the top floor
  3. every light on the bottom floor
  4. every other light in the whole house (starting from the first one)
  5. every other light in the whole house (starting from the second one)
  6. every light other than the first and last one

questions

reflect on the following questions
  1. why are the counter initialization values from 0 to 7?
  2. if you don't know the length of your array, what should you use for your looping condition?
  3. what happens when the looping condition goes beyond the array length?
  4. what is another way to write i++ (look at the other dropdowns for the incrementer)?
Back to Projects