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

The program is designed to do the following:

  1. Starts by generating two random integers (between 1 and 99 inclusive) and asks the user to enter the sum of the two integers, or enter -1 (minus one) to quit;
  2. For each run of the while loop, the program reads the user input, and determines if the user's answer is correct.
  3. If the answer is correct, it increments the count variable by 1 for the number of correct answers, and gives the feedback "Correct! "
  4. If the answer is incorrect, it simply gives the feedback "Sorry. Not correct. "
  5. For each run of the while loop, the , the loopCounter is incremented by 1
  6. When the user enters -1, the while loop stops and the program tells the user how many correct answers she/he has got out of a total number of tries.

There are two JavaScript functions used in this program:

You can find more about various Math functions provided by JavaScript at http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/ref_r-r.htm

The Task:

Right now, the program has a bug that prevents it from determining correct answers and giving the right feedback. It'll say "Correct!" even when the user input is incorrect. Consequently, it cannot get the correct number of correct answers (sorry about the double use of "correct") when the user quits. Your task is to find and fix this bug.

This bug is somewhat subtle and may not be easily identified through a debugger like Netscape. Please view the source code of the page carefully and see if you can find it. When you find the bug, write down (in HTML web page format) what the problem is, and how it can be fixed.

Bonus Points:

You'll earn bonus points if you can modify the program so that the arithmetic practice is on the product of two integers (instead of the sum of two integers), and the keyboard input to quit the program is "stop".