Loops Assignment Part II
Finding the bug in a loop
The first thing I did, as I looked at the loop on this problem, was erased all of the extra text and writing at the bottom after the script, so I didn't have to bother with it. I then started to look at the "while" script and see if I could find the error that was giving me the feedback that every answer was correct.
The first thing I tried was that I moved the input value. I noticed that the inputvalue=parseInt(inputtext); command was actually listed before the "while" loop. I was not sure if this was correct, so I cut and pasted it on line 51, directly below the line that starts the while loop. This did not solve the problem of correct feedback for every question.
So then, I figured the "bug" had to be somewhere between lines 52 and 62, where the correct and incorrect "if...else if" statements were. As I looked at the script, I couldn't find anything wrong. I check over it several times. Finally, I thought of checking the operators, as I know that = and == mean different things. And there I found the solution on page 61 of the Flanagan text. "=" is an assignment operator, and since this is what was on line 54, it was automatically telling the script to read every response(except that of -1) as correct. So I changed the operator to "==" which is a test for equality, and the script worked well.
I did not bother to move the inputvalue line back, as I had a working script.
Here is the working script for this assignment.