NEW
Font size
WorksheetsJavascript Quiz 2
Total questions: 15
Worksheet time: 8mins
How many choices are possible when using a single if-else statement?
1
2
3
4
What Javascript code matches this statement:
Their name is Kim and they are less than 16 years old
if (name = "Kim" && age < 16 )
if (name = "Kim" || age < 16 )
if (name === "Kim" && age < 16 )
if (name === "Kim" || age < 16 )
What Javascript code matches this statement:
The player's health is 0 and they still have a life remaining.
if (health == "0" && lives > "0")
if (health === 0 && lives >= 0)
if (health <1 && lives > 0)
if (health === 0 && lives > 0)
What Javascript code matches this statement:
The player has gathered at least 300 coins or reached the end of the level.
if ("coins" >= 300 && "end" == true)
if (coins >= 300 || end == true)
if ("coins" >= 300 OR "end" == true)
if ("coins" >= 300 || "end" == true)
What kind of statement is an If statement?
comparison statement
anecdotal statement
conditional statement
looping statement
What kind of operators do If statements use to test conditions?
comparison operators
arithmetic operators
array operators
bitwise operators
What happens when an If statements conditional is not true?
the if statement executes
Nothing happens
the if statement start over
all options are correct
What will be the output of the following JavaScript code?
if (10 > 5) {
var outcome = "if block";
}
outcome;
10
5
if block
none
What will be the output of the following JavaScript code?
if ("cat" === "dog") {
var outcome = "if block";
} else {
var outcome = "else block";
}
outcome;
if block
else block
both a And b
none
What will be the output of the following JavaScript code?
var grade='B';
var result;
switch(grade)
{
case 'A':
{
result+="10";
break;
}
case 'B':
{
result+=" 9";
break;
}
case 'C':
{
result+=" 8";
break;
}
default:
result+=" 0";
}
document.write(result);
10
9
8
0
Which of these is not a type of loop in JavaScript?
while
for
do while
repeat
Which of these expressions is NOT a valid way to add 1 to a variable in JavaScript?
x++
x+=1
x=x+1
x+
Let's say you have an x variable that starts as 0. If you want your while loop to stop once the x variable equals 400, what condition would you use?
x < 400
x > 400
x == 400
x >= 400
Let's say you want to repeat a shape 20 times. Which for loop would help you code that?
for (var i = 1; i < 20; i++) { }
for (var i = 0; i < 20; i++) { }
for (var i = 0; i <= 20; i++) { }
for (var i = 0; i > 20; i++) { }
Let's say you want to repeat a shape horizontally across the 400x400 canvas, with 40 pixels between each shape. Which for loop would help you code that?
for (var x = 0; x > 400; x += 40) { }
for (var x = 0; x < 400; x++) { }
for (var x = 0; x < 400; x += 40) { }
for (var x = 0; x > 400; x++) { }
