Question

Given the following JavaScript code, what will be displayed on the web page? var x =...

Given the following JavaScript code, what will be displayed on the web page?

var x = 5;

var y = 12;

while (x < y)

{

     document.write(x);

     document.write("<br>");

     x=x+3;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the output produced :

5
8
11


Explanation:

While loop executes until the given condition is true .
ie) in this case until x is less than y.


1 st Iteration :

It prints 5 since 5 is less than 12 .
<br> means break line which is new line.

x=x+3
This means
x = 5+3 = 8 now .
x is 8 now .


2 ns iteration
It prints 8.
new line.

x= 8+3 = 11
x is 11 now.

3rd iteration :

11 is leass than 12 hence .

it prints 11.

x= 11+3

x is 14 now.

4th iteration

Is x still less than y?

is 14 less than 12?

No hence program ends.

Add a comment
Know the answer?
Add Answer to:
Given the following JavaScript code, what will be displayed on the web page? var x =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following JavaScript code, what will be displayed on the web page? var i, j;...

    Given the following JavaScript code, what will be displayed on the web page? var i, j; for (i=1; i<=3; i++) {      for (j=2; j<=5; j++)      {            document.write(i+ "," + j + "; ");      }      document.write("<br>"); } 2,3; 3,4; 4,5; 4,6;

  • Given the following JavaScript code, what will be displayed on the web page? var pho =...

    Given the following JavaScript code, what will be displayed on the web page? var pho = new Array(); for (var i = 0; i< 7; i++) {      pho[i] = (i*i) + 3; }            for (var i = 0; i< 7; i++) {      document.write(i + " => " + pho[i] + "<br>"); } 1 => 4 2 => 7 3 => 12 4 => 19 5 => 28 6 => 39

  • Consider the following JavaScript skeletal program: //the main program var x: function sub1 () { var...

    Consider the following JavaScript skeletal program: //the main program var x: function sub1 () { var x: function sub2 () { } } function sub3 () { } Assume the execution of this program is in the following unit order: main calls sub1 sub1 calls sub2 sub2 calls sub3 a. Assuming static scoping, which declaration of x is the correct one for a reference to x in: i. sub1 ii. sub2 iii. sub3 b. Repeat part a, but assume dynamic...

  • JavaScript 30. What will be displayed after the following code is entered and run if the...

    JavaScript 30. What will be displayed after the following code is entered and run if the user enters "9 am" at the first prompt and "N-215" at the second prompt? If you think there is an error, describe how you would fix it. function examTime() { var time = prompt("What time is the exam?"); var room = prompt("What room is the exam in?"); showIt(time, room); } function showIt(a, b) { document.write("Your exam is in room " + a + "...

  • Exercise 30 refer to the following code: var vacation = prompt("What do you want to do...

    Exercise 30 refer to the following code: var vacation = prompt("What do you want to do during Spring Break? ↵ Type S for skiing, F for fishing, H for hiking,8 J for learning JavaScript.", " "); if (vacation == 'S') document.write("You should go to Aspen.<br />"); if (vacation == 'H') document.write("Be sure to buy good hiking boots.<br />"); if (vacation == 'F') document.write("Worms make good bait.<br />"); if (vacation == 'J') document.write("You're gonna have soooo much fun!<br />"); 30. Rewrite...

  • This is my code so far: <!DOCTYPE html> <html> <head> <title>JavaScript is fun</title> <meta charset="utf-8" />...

    This is my code so far: <!DOCTYPE html> <html> <head> <title>JavaScript is fun</title> <meta charset="utf-8" /> </head> <body> <script type ="text/javascript"> //declare a variable and store text in it var x = "JavaScript is fun"; //write the variable 5 times document.write(x + x + x + x + x); //store 5 as string in variable x x = "5"; //store 3 as string in variable y var y = "3"; //write the value x + y to the document document.write("<br>");...

  • Please help me with the following requirements for JavaScript. Write a function to take a temperature value in Celsius a...

    Please help me with the following requirements for JavaScript. Write a function to take a temperature value in Celsius as an argument and return the equivalent temperature in Fahrenheit, basing it on the code from Hour 2. //Original Code <!DOCTYPE html> <html> <head>     <title>Fahrenheit From Celsius</title> </head> <body>     <script>         var cTemp = 100;  // temperature in Celsius         var hTemp = ((cTemp * 9) /5 ) + 32;         document.write("Temperature in Celsius: " + cTemp + " degrees<br/>");         document.write("Temperature in Fahrenheit: "...

  • List the five implementation models of parameter passing. Consider the following closure in JavaScript: 1- function...

    List the five implementation models of parameter passing. Consider the following closure in JavaScript: 1- function makeAdder(x) { 2- return function(y) {return x + y;} 3- } . . . 4- var add1 = makeAdder(0); 5- var add2 = makeAdder(10); 6- document.write(add1(20)); 7- document.write(add2(20)); Questions: a) Show the output. b) What is the closure subprogram in this example? c) Explain how the variable x referenced at line 2 is bound.

  • 1. Given the following code snippet, what is the scope of the variable pen on Line...

    1. Given the following code snippet, what is the scope of the variable pen on Line 1? <script> 1.    var pen = "ball point"; 2.    var pencil = "0.7mm lead"; 3.    function writeIt() 4.    { 5.          document.write(I have a " + pen + " pen."); 6.          pen = "gel ink"; 7.         document.write("You have a " + pen + " pen."); 8.          var pencil = "0.5mm lead"; 9.          document.write("I prefer pencils with " + pencil + "."); 10.   } <script> A. global B....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT