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

Question: Given the following JavaScript code: <script language=javascript type=

ID: 3851423 • Letter: Q

Question

Question: Given the following JavaScript code:

  <script language=javascript type="text/javascript">

                for (i=0;i < 10; i++) {

          document.write(i);

         }

    </script>

What is the output?

How would you modify the code so that it prints the numbers backwards? Please list your codes.

How would you modify the code so that it prints only the even numbers? Please list your codes.

How would you modify the code so that it sums all the values of i and prints the final sum?   Please list your codes.   

Explanation / Answer

output is : 0123456789

Code for printing numbers in backwards:

<script language="javascript" type="text/javascript">

for(i=9;i>=0;i--){

document.write(i);

}

</script>

Code for printing only even numbers:

<script language="javascript" type="text/javascript">

for(i=0;i<10;i++){

if((i%2)==0){

document.write(i);

}

}

</script>

Code for calculating the sum of values of i:

<script language="javascript" type="text/javascript">

var finalSum=0;

for(i=0;i<10;i++){

finalSum = finalSum + i;

}

document.write(finalSum);

</script>

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