Wednesday, February 14, 2018

[Programming] Using Loops

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:

  1. while
  2. for
Each loop is used to accomplish different tasks. Generally, they are used to repeat a task many times. You can find more information about using loops by clicking this link.

Content Rubric

Your program will include three loops total:

  • TWO while loops.
  • One for loop.

while loop #1 Rubric

  1. Create a variable named loopCount and assign it a value of 0. [2 Points]
  2. Create a while loop that executes as long as loopCount is less than 10,000. [2 Points]
  3. Inside the while loop use console.log to print "Do you know the way?" on the console. [2 Points]
  4. Increment the loopCount variable by 1 each time through the loop. [2 Points]
  5. When the loop exits use console.log to print "I hope you know the way." on the console. [2 Points]

while loop #2 Rubric

  1. Create a while loop that executes as long as loopCount is greater than 0. [2 Points]
  2. Inside the while loop use console.log to print "Yes, Knuckles, I know the way!" on the console. [2 Points]
  3. Decrement the loopCount variable by 1 each time through the loop. [2 Points]
  4. When the loop exits use console.log to print "Stop asking me Knuckles!" on the console. [2 Points]

for loop Rubric

  1. Statement 1 of the loop creates a variable named numberCount and assigns it a value of 0. [2 Points]
  2. Statement 2 of the loop checks to see if numberCount is less than or equal to 10,000. [2 Points]
  3. Statement 3 increases the value of numberCount by 2 each time through the loop. [2 Points]
  4. Each time through the loop, use console.log to print "The number count is currently equal to" + numberCount [2 Points]

Process Rubirc

  1. Program is written using JavaScript. [5 Points]
  2. File Name is: lastname_firstname_using_loops [5 Points]
  3. File Format is JavaScript (.js) [5 Points]
  4. File is submitted to Focus by 02/23/18 at 11:59PM. [15 Points]