Background
Using a loop statement allows a computer program to repeat steps over and over. It is extremely useful for counting or scanning files for data. For example you might want to scan a document for the word "potato" or "rutabaga". A loop is one way to accomplish this.
Directions
For this activity you will write some simple loops using JavaScript. The most common loops are:
- while
- for
Content Rubric
Your program will include three loops total:
- TWO while loops.
- One for loop.
while loop #1 Rubric
- Create a variable named loopCount and assign it a value of 0. [2 Points]
- Create a while loop that executes as long as loopCount is less than 10,000. [2 Points]
- Inside the while loop use console.log to print "Do you know the way?" on the console. [2 Points]
- Increment the loopCount variable by 1 each time through the loop. [2 Points]
- When the loop exits use console.log to print "I hope you know the way." on the console. [2 Points]
while loop #2 Rubric
- Create a while loop that executes as long as loopCount is greater than 0. [2 Points]
- Inside the while loop use console.log to print "Yes, Knuckles, I know the way!" on the console. [2 Points]
- Decrement the loopCount variable by 1 each time through the loop. [2 Points]
- When the loop exits use console.log to print "Stop asking me Knuckles!" on the console. [2 Points]
for loop Rubric
- Statement 1 of the loop creates a variable named numberCount and assigns it a value of 0. [2 Points]
- Statement 2 of the loop checks to see if numberCount is less than or equal to 10,000. [2 Points]
- Statement 3 increases the value of numberCount by 2 each time through the loop. [2 Points]
- Each time through the loop, use console.log to print "The number count is currently equal to" + numberCount [2 Points]
Process Rubirc
- Program is written using JavaScript. [5 Points]
- File Name is: lastname_firstname_using_loops [5 Points]
- File Format is JavaScript (.js) [5 Points]
- File is submitted to Focus by 02/23/18 at 11:59PM. [15 Points]