Exercise Weekend

Goal: In the Looping with for lesson, we learned:

• The three parameters of a `for` loop
• The `length` property in JavaScript
• How to use a `for` loop both with and without arrays

Practice utilizing for loops in a variety of ways by completing the exercises detailed below.

## Warm Up

• What is the difference between `for` and `forEach()` loops? Describe to your partner a specific case in which you would use one over the other.
• How does a for loop 'know' when to stop looping?
• What else can we do with the first parameter in a `for` loop?

## Code

### Count Up By

Create a program that takes two numbers - one to count to and another to determine what multiple to use to get there.

Here is some sample input:
Count to: 30
Count by: 5
Output: 5, 10, 15, 20, 25, 30

Count to: 50
Count by: 7
Output: 7, 14, 21, 28, 35, 42, 49

Don't forget to consider how to handle any input that might be submitted:

• empty values (user just presses enter)
• negative numbers
• count by number is larger than the count to numbers

### Turn forEach() into For

Go back through the looping practice problems, and redo one of them with a `for` loop instead of a `forEach()` loop.

### Word Puzzle

Create a website that uses a method to replace vowels in a string with the dash symbol "-" to create a word puzzle to solve. Hide the original string when you show the resulting word puzzle, so that another person can try and guess it.

Example:

String Input: "Believe you can and you're halfway there. Theodore Roosevelt"

Puzzle Output: "B-l--v- y-- c-n -nd y--'r- h-lfw-y th-r-. Th--d-r- R--s-v-lt"

Do this without regular expressions. (If you don't know what a regular expression is yet, don't worry - we will be covering them in a future lesson.)

## Peer Code Review

• Is the business logic and user interface logic distinctly separate?
• Are variable names descriptive and in lower camelCase?
• Does the code have proper indentation and spacing throughout?
• Are for loops being used correctly?
• Are `forEach()`loops being used correctly?

Lesson 16 of 16
Last updated July 30, 2020