Question: This application will give you a chance to use a for loop. Use the prompt dialog box to ask the user to enter a number
This application will give you a chance to use a for loop. Use the prompt dialog box to ask the user to enter a number from 1 through 100.
Then, display a dialog box asking the user if they want to enter another number. The user will enter y or n. If the user enters y, input the next number 1 through 100, then ask if they want to enter another number.
Finally, it adds all the numbers from each of the users entries and displays the sum of the numbers in the page like this:
The sum of the numbers 1 - 5 is 15.
The sum of the numbers 1 - 89 is 4005.
Open this HTML file:
exercises_extra\ch03\sum_numbers.html
In the script element, add a do-while loop that prompts the user for an entry from 1 through 100. If the entry is invalid, display an alert box with this message: Please enter a number between 1 and 100. Then, continue the loop until the entry is valid.
After the do-while loop, code a for loop that sums the numbers, and then display the second dialog box above. For instance, the sum for an entry of 4 is 1 + 2 + 3 + 4.
Add a do-while loop around all of the code that uses the second dialog box above to determine whether the first dialog box should be displayed again so the user can enter another number. The application should end for any entry other than y.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
