🚀 Basics Day 4: Pre-Class Exercises 🚀

Pre-Class In-Class

Follow Along (Loops)

Follow along and implement the code in the Loops module.


Input:


Output:

Simple Loop with Variations (Loops)

  1. Create a loop in the simpleLoopMain function. Make the loop run 6 times, adding "hello" to myOutputValue with each loop iteration.
  2. What happens if counter starts as a number other than zero?
  3. What happens if, inside the loop, you alter the counter by adding a number other than one?
  4. What happens if you change the condition inside the loop from counter < 6 to counter <= 6?

Input:


Output:

Loop within Loop (Loops)

  1. Create nested loops in the loopWithinLoop function, where the outer loop runs 3 times and the inner loop runs 3 times per outer loop. Concatenate "hello" to myOutputValue in the inner loop. How many times do we see "hello"?
  2. Add "<br />" to myOutputValue in the outer loop so that the program makes a new line for each outer loop.
  3. What happens if outerCounter starts as a number other than zero?
  4. What happens if innerCounter starts as a number other than zero?
  5. What happens if, inside the loop, you alter outerCounter by adding a number other than one?
  6. What happens if, inside the loop, you alter innerCounter by adding a number other than one?
  7. What happens if you change the outer loop condition from outerCounter < 3 to outerCounter <= 3?
  8. What happens if you change the outer loop condition from innerCounter < 3 to innerCounter <= 3?
  9. Update loop conditions to use input to control how many times the loops run.
  10. Update our code such that the inner loop runs twice the number of times as the outer loop. How many more times do we see "hello"?

Input:


Output:

Infinite Loop (Loops)

Make a loop that never stops running. Be prepared to stop/kill this Chrome tab, because it will freeze.


Input:


Output: