Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScript:This application will give you a chance to use a for loop. It asks th

ID: 3787518 • Letter: J

Question

JavaScript:This application will give you a chance to use a for loop. It asks the user to enter anumber from 1 through 100 with the prompt dialog.

Then, it adds all the numbers from one to the user’s entry and displays the sum of thenumbers in an alert dialog box.

Then, to give the user a chance to do multiple entries.

1. Use the code below:
2. In the script element, add a do-while loop that prompts the user for an entry from 1through 100. If the entry is invalid, display an alert box with this message: “Pleaseenter a number between 1 and 100”. Then, continue the loop until the entry is valid.
3. After the do-while loop, code a for loop that sums the numbers, and then display thesecond dialog box above. For instance, the sum for an entry of four 1 + 2 + 3 + 4.
4. Add a do-while loop around all of the code that uses the third dialog box above todetermine whether the first dialog box should be displayed again so the user can enteranother number. The application should end for any entry other than “y”.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Sum of Numbers</title>
    <script>
  
    </script>
</head>
<body>
    <main>
        <!-- Will show after JavaScript has run -->
        <h1>Thanks for using the Sum of Numbers application!</h1>
    </main>
</body>
</html>

Explanation / Answer

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Sum of Numbers</title>

    <script>

        do

        {

            do

            {

                var theNumber = prompt("Enter first number", "10");

                theNumber = parseInt(theNumber);

                var numberOfLoops = (theNumber);

                numberOfLoops = parseInt(numberOfLoops);

                if(isNaN(theNumber) || theNumber <1 || theNumber > 100)

                {

                    alert("Please enter a number between 1 and 100");

                }

            }

            while (isNaN(theNumber) || theNumber <1 || theNumber > 100);

               

            var sum = 0;

            for (var counter = theNumber; counter>=1; counter--)

            {

                alert(counter);

Sum = (theNumber + counter);

            }

            alert(sum);

            again = prompt("Do it again? ('y' for yes)")

        }

        while(again === 'y');

    </script>

</head>

<body>

    <main>

        <!-- Will show after JavaScript has run -->

        <h1>Thanks for using the Sum of Numbers application!</h1>

    </main>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote