JavaScript Control Structures Test
What is the proper operator for "not equals" in JavaScript? =! != ~= NOT EQUALS
!=
What symbol represents the and operator in JavaScript? AND and & &&
&&
How can we check if a variable num is even? num.isEven() will be true (num % 2 == 0) will be true (num % 2 == 0) will be false (num / 2 == 0) will be true
(num % 2 == 0) will be true
How many times will this program print "hello"? var i = 10; while (i > 0) { println("hello"); i--; } 0 10 i This code will loop infinitely
10
What will be the value of sum after this code runs? var START = 1; var END = 4; function start(){ var sum = 0; for(var i = START; i <= END; i++){ sum += i; } } 10 4 1 40
10
In the following code, what will be the last number to print to the screen before the program finishes? for (var i = 0; i < 10; i++) { if (i % 2 == 0) { println(i); } else { println(2 * i); } } 10 20 9 18
18
How many possible values can Randomizer.nextBoolean() return? 0 1 2 3
2
How many times will the following code print "hello"? for (var i = 0; i < 8; i += 2) { println("hello"); } 0 2 4 8
4
How many times will the following code print "hello"? for (var i = 3; i < 8; i++) { println("hello"); } 3 5 6 8
5
How many times will the following program print "hello"? for (var i = 0; i < 5; i++) { println("hello"); } 4 5 6 i
5
What is the proper way to compare if two values are equal in a boolean expression in JavaScript? = == EQUALS is
==
Why do we use constant variables? To avoid having "magic numbers" in our code To give values a readable name, so that their purpose is clear To let us easily change the behavior of our program by only having to change a value in one place All of the above
All of the above
Which of the following returns a random number between 1 and 10? randomInt(1, 10) randInt(1, 10) Randomizer.int(1, 10) Randomizer.nextInt(1, 10)
Randomizer.nextInt(1, 10)
How many times will this program print "hello"? var i = 50; while (i < 100) { println("hello"); } 0 50 100 This code will loop infinitely
This code will loop infinitely
After the following code runs, what is the value of isWeekend? var isSaturday = true; var isSunday = false; var isWeekend = isSaturday || isSunday; true false "isWeekend" "isSaturday || isSunday"
True
Which of the following is not a valid value for a boolean? True False Yes The above are all valid
Yes
What statement can we use inside of a loop to end it? println break for else
break
What kind of statement allows us to run a block code only if a certain condition is true? if statement break statement else statement for loop
if statement
What kind of statement allows us to run one block of code if one condition is true, and a separate block of code otherwise? if statement break statement if/else statement for loop
if/else statement
What is the term for the value that signals the end of user input? sentinel break -1 done
sentinel
Which of the following is a good example of a proper constant variable name? var max_value = 100; var MAX_VALUE = 100; var Max_Value = 100; var maxValue = 100;
var MAX_VALUE = 100;
Which of the following is correct loop and a half structure? while(condition){ //code } for(var i = 0; i <= 1.5; i++){ //code } while(true){ //code if(condition){ break; } //code } for(var i = 0; i < 2; i++){ //code break; //code }
while(true){ //code if(condition){ break; } //code }
What symbol represents the or operator in JavaScript? OR or | ||
||