Northcentral Technical College Introduction To Programming
10-152-310
Introduction to Programming with JavaScript NTC 10-152-310

Learning Plan 5 5.1 Lab 7

# 5.1 Lab 7

#### File: /Learning Plan 5/5.1lab7.html

### Student

- Name:
- Section:
- Email:

## Part 1 - Lab Steps

1. Open this file in Firefox and Microsoft Visual Studio.
2. Add your name, section, and email
3. Open the file "/Learning Plan 5/jsFiles/5.1lab7.js" in jEdit.
4. Locate the function named "lab51_7Part1()".
5. Add code after the line: `// PART 1: YOUR CODE STARTS AFTER THIS LINE:` to complete the lab.
6. Variable declarations section
   1. Write a comment that identifies this coding section.
   2. Declare a `counter` variable.
   3. Declare a `loopMaximum` variable.
   4. Declare a `total` variable.
7. Assignments section
   1. Write a comment that identifies this coding section.
   2. Assign one `(1)` to the `counter` variable.
   3. Assign zero `(0)` to the `total` variable.
8. Processing Section
   1. Write a comment that identifies this coding section.
   2. Ask the user to enter the number of times they would like to loop and assign the entry to the `maximumLoop` variable.
   3. Convert the entered value to a number.
   4. Using a `while` loop perform the following the number of times that the user entered. For example, if the user entered 5 then loop 5 times. Since you started the loop `counter` variable at one, how do you do this? (Hint: (counter <= maximumLoop)) Notice the "="?
      1. Add the counter variable into the `total` variable. Use the compound operator `+=`.
      2. Write the `counter` variable and the `total` variable to the page as in the sample output.
      3. Increment the `counter` variable.
   5. After the loop is done, write the total to the page as in the sample.

#### Sample Part 1 Output:

    In loop 1 the total is 1.
    In loop 2 the total is 3.
    In loop 3 the total is 6.
    In loop 4 the total is 10.
    In loop 5 the total is 15.

    The final total is 15.

### Your Part 1 Output:

## Part 2 - Lab Steps

- Open this file in Firefox and Microsoft Visual Studio.
- Add your name, section, and email
- Open the file /Learning Plan 5/jsFiles/5.1lab7.js in Microsoft Visual Studio.
- Locate the function named lab51_7Part2() in the javascript file.
- Remove the existing `document.write();` function call and write a JavaScript program in that function that completes the following.
- Variable declarations section
  1. Write a comment that identifies this coding section.
  2. Declare a variable named `counter`.
  3. Declare a variable named `loopMaximum`.
  4. Declare a variable named `product`.
  5. Declare a variable named `seven`.
- Assignments section
  1. Write a comment that identifies this coding section.
  2. Assign the value `1` to the `counter` variable.
  3. Assign the value `20` to the `loopMaximum` variable.
  4. Assign the value `7` to the `section` variable.
- Looping section
  1. Write a comment that identifies this coding section.
  2. Create a `while` loop that will run 20 times using the `counter` and `loopMaximum` variables.
  3. In the loop perform the following:
     1. Multiply `counter` by `seven` and assign the results to the `product` variable.
     2. Output the results as in the sample output.
     3. Increment the `counter` variable.

#### Part 2 Sample Output

    7 x 1 = 7
    7 x 2 = 14
    7 x 3 = 21
    7 x 4 = 28
    7 x 5 = 35
    7 x 6 = 42
    7 x 7 = 49
    7 x 8 = 56
    7 x 9 = 63
    7 x 10 = 70
    7 x 11 = 77
    7 x 12 = 84
    7 x 13 = 91
    7 x 14 = 98
    7 x 15 = 105
    7 x 16 = 112
    7 x 17 = 119
    7 x 18 = 126
    7 x 19 = 133
    7 x 20 = 140

#### Your Part 2 Output

### 5.1 Assignment 1

- 5.1 Assignment 1