What's plus ?

Week 4 Assignment Part 2: A While Loop for Practicing Arithmetic Calculations

The program is designed to do the following:

1. When the page loads into the browser, it generates two random integers (between 1 and 99 inclusive) and puts the two numbers in two textboxes.
2. It asks the user to enter the sum of the two integers.
3. It reads the user input, and determines if the user's answer is correct.
4. If the answer is correct, it increments the count variable by 1 for the number of correct answers, and gives the feedback "Correct! "
5. If the answer is incorrect, it gives the feedback "Sorry, the correct answer is ... . "
6. The program counts the number of correct answers and the total number of tries, and displays the result.

There are two JavaScript functions used in this program:

• Math.random()
• Math.round()

The first function returns a random number between zero and one, such as 0.9756070656669248 or 0.4477332493847449.

In the example, we multiply the random number by 100 to fit our needs, getting 97.56070656669247 or 44.77332493847449.

The second function rounds a number to its nearest integer:

Math.round(97.56070656669247) returns 98.
Math.round(44.77332493847449) returns 45.

To see a demo of the above functions, visit http://courses.dsu.edu/cet756/lessons/JavaScript/functions/mathrandom_and_mathround.htm