Given the following JavaScript code, what will be displayed on the web page?
var k=1; var m=0; var p=0;
while (k<=4)
{
k++;
for (p=1; p<=4; p++)
{
document.write(p +" ");
}
document.write("<br>");
}
web page will display
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
let use dissect the code
1. var k=1; var m=0; var p=0; // here k is assigned value 1
2. while (k<=4) // this while loop will continue to run when k is less than equal to 4
3. {
4. k++; // each iteration we are incrementing k value by one
5. for (p=1; p<=4; p++) // for that will loop from p = 1 to 4 increment by 1
6. {
7. document.write(p +" "); // print value of p for each p and space after it
8. }
9. document.write("<br>"); // add a line break
10. }
thus inner for loop line(5-8) print a line with values 1 to 4 separated by space as 1 2 3 4
and outer while loop(2-9) runs 4 time printing output of inner for loop line by line
Given the following JavaScript code, what will be displayed on the web page? var k=1; var...
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; }
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
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;
What is the problem with this code? <html> <body> <script type="text/javascript"> //Declare variables var numStudents; var index; var sName; var ES = ""; var BR = "<br />"; var PA = "<p />"; //Print statement document.write("Student Name Entry Program" + PA); //Prompt for number of students to add numStudents = prompt("Enter the number of student names to add: "+ ES); //Loop through numStudents of times, prompting for student names for(index = 1; index <= numStudents: index++) { sName = prompt("Enter...
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 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...
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...
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....
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: "...