Question

In: Computer Science

Display 10, 17, 26, 37, 50, 65, 82, 101, 122, 145, 170, 197, …, 626. Loop...

  1. Display 10, 17, 26, 37, 50, 65, 82, 101, 122, 145, 170, 197, …, 626. Loop or While
  2. Multiply all even numbers from 2 to 12 and show the final result.

USING HTML JAVASCRIPT

Solutions

Expert Solution

Dear Student ,

As per requirement submitted above kindly find below solution.

Question 1:

Here new web page with name "1Sample.html" is created which contains below code.

1Sample.html :

<!DOCTYPE html>

<html lang="en">

    <head>

        <!-- title for web page -->

        <title>Sequence using Javascript</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1">

        

    </head>

    <body>

    <!-- script is used for javascript -->

    <script>

        var odd=7;//declaring variable to store odd number

        var i=10;

        //using while loop loop

        while(i<=626)

        {

            //display value of i

            document.write(i+" , ");

            //add odd into i

            i=i+odd;

            //add 2 into odd

            odd=odd+2;

        }

    </script>

    </body>

</html>

==================================

Output :Open web page 1Sample.html in the browser and will get the screen as shown below.

Screen 1:1Sample.html

**********************************

Question 2:

<!DOCTYPE html>

<html lang="en">

    <head>

        <!-- title for web page -->

        <title>Multiplication of even numbers</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1">

    </head>

    <body>

    <!-- script is used for javascript -->

    <script>

       

        var i=1; //declaring variable as strting number

        var evenTotal=1;//variable used to store multiplication

        //using while loop loop

        while(i<=12)

        {

            //checking number

            if(i%2==0)

            {

                //if number is even then

                //multiply ecenTotal by i

                evenTotal=evenTotal*i;

            }

            //increment value of i

            i=i+1           

        }

        //display multiplication of even numbers from 1 to 12

        document.write("Multiplication of even numbers from 1 to 12 : "+evenTotal);

    </script>

    </body>

</html>

**********************************

Screen 1:

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

4. Insert 21, 9, 28, 4, 15, 26, 30, 10, 2, 37, 17, 88 into the...
4. Insert 21, 9, 28, 4, 15, 26, 30, 10, 2, 37, 17, 88 into the AVL Tree. Have the balancing factor. Don't write a program. Just please manually solve the problem. Thanks.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT