Sei sulla pagina 1di 5

Assignment 4 - JavaScript Will Not Be Accepted After April 8th at 10am

1.

document.write("go "); document.write("fast");

What message will this code output?

go fast

2.

var value; value = 1.2; value = value + 2.4;

What value is stored in value after this code executes?

3.6

3.

var fork_link; fork_link = 2; alert(fork_link + 5);

What value is stored in fork_link after this code executes?

What will be displayed by the alert when this code runs?

4.

var number; number = 3; number = number * 4; document.write(number);

What will this code output to the user?

12

5.

var myValue; var yourValue; myValue = 5; yourValue = 3; document.write(myValue - yourValue); myValue = myValue + yourValue;

What will this code output to the user when it runs?

2
What will the value of myValue be after this code runs?

6.

if (number < 0) alert("negative");

What would happen if number was bigger than zero?

nothing would happen


What would happen if number was smaller than zero?

an alert box displays the message "negative"


What would happen if number was equal to zero?

nothing would happen

7.

if (num <= 0) alert("too little"); else alert("too large");

What would happen if num was bigger than zero?

an alert box displays the message "too large"


What would happen if num was smaller than zero?

an alert box displays the message "too little"


What would happen if num was equal to zero?

an alert box displays the message "too little"

8.

var day_of_the_week; var wakeUp; day_of_the_week = "Monday"; if (day_of_the_week == "Sunday") wakeUp = "8:00"; else if (day_of_the_week == "Saturday") wakeUp = "11:00"; else wakeUp = "6:15";

What is the value of wakeUp after this code executes?

6:15
What is the value of day_of_the_week after this code executes?

Monday
What will this code print on the screen?

nothing

9.

var my_num; my_num = 5; if (my_num < 10) document.write("ten "); if (my_num < 8) document.write("eight "); if (my_num < 6) document.write("six "); if (my_num < 4) document.write("four ");

What will this code print on the screen?

ten eight six

10.

var by_num; by_num = 5; if (by_num < 10) document.write("ten "); if (by_num < 4) document.write("four "); else document.write("again ");

What will this code print on the screen?

ten again

11.

var i; i = 1; while (i <= 3){ document.write("#"); i = i + 1; }

How many number signs will be printed on the screen?

3
What is the value of i after this code executes?

12.

var j; j = 1; while (j <= 7){ document.write("#"); j = j + 2; }

How many number signs will be printed on the screen?

4
What is the value of j after this code executes?

13.

var count; count = 1; while (count <= 5){ count = count + 1; document.write(count); }

What will the output be when this code runs?

23456

14.

var ktoon; ktoon = 0; while (ktoon > 5){ document.write("$"); ktoon = ktoon + 1; } var times; times = 2; while (times < 5){ document.write(times); times = times - 1; }

What will the output be when this code runs?

No output; the loop condition is always false

15.

What will the output be when this code runs?

Infinite loop will print numbers starting at 2, decreasing to negative infinity without stopping.

16.

var outer; var inner; inner = 1; while (inner <= 5){ outer = 1; while (outer <= 3) { document.write("*"); outer = outer + 1; } inner = inner + 1; }

How many stars (*) will be printed on the screen?

15

Potrebbero piacerti anche