Goal: In the last lesson, we learned:
for
loopfor
loop both with and without arraysPractice utilizing for loops in a variety of ways by completing one of the exercises detailed below.
for
and Array.prototype.forEach()
loops? Why should you generally favor Array.prototype.forEach()
?for
loop and what is it for?Complete one of the exercises below.
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:
Go back through the looping practice problems, and redo one of them with a for
loop instead of a forEach()
loop.
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.)
forEach()
loops being used correctly?