wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Javascript Quiz 2

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

How many choices are possible when using a single if-else statement?

a)

1

b)

2

c)

3

d)

4

2.

What Javascript code matches this statement:

Their name is Kim and they are less than 16 years old

a)

if (name = "Kim" && age < 16 )

b)

if (name = "Kim" || age < 16 )

c)

if (name === "Kim" && age < 16 )

d)

if (name === "Kim" || age < 16 )

3.

What Javascript code matches this statement:

The player's health is 0 and they still have a life remaining.

a)

if (health == "0" && lives > "0")

b)

if (health === 0 && lives >= 0)

c)

if (health <1 && lives > 0)

d)

if (health === 0 && lives > 0)

4.

What Javascript code matches this statement:

The player has gathered at least 300 coins or reached the end of the level.

a)

if ("coins" >= 300 && "end" == true)

b)

if (coins >= 300 || end == true)

c)

if ("coins" >= 300 OR "end" == true)

d)

if ("coins" >= 300 || "end" == true)

5.

What kind of statement is an If statement?

a)

comparison statement

b)

anecdotal statement

c)

conditional statement

d)

looping statement

6.

What kind of operators do If statements use to test conditions?

a)

comparison operators

b)

arithmetic operators

c)

array operators

d)

bitwise operators

7.

What happens when an If statements conditional is not true?

a)

the if statement executes

b)

Nothing happens

c)

the if statement start over

d)

all options are correct

8.

What will be the output of the following JavaScript code?


if (10 > 5) {


var outcome = "if block";


}​


outcome;

a)

10

b)

5

c)

if block

d)

none

9.

What will be the output of the following JavaScript code?


if ("cat" === "dog") {


var outcome = "if block";


} else {


var outcome = "else block";


}


outcome;

a)

if block

b)

else block

c)

both a And b

d)

none

10.

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);

a)

10

b)

9

c)

8

d)

0

11.

Which of these is not a type of loop in JavaScript?

a)

while

b)

for

c)

do while

d)

repeat

12.

Which of these expressions is NOT a valid way to add 1 to a variable in JavaScript?

a)

x++

b)

x+=1

c)

x=x+1

d)

x+

13.

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?

a)

x < 400

b)

x > 400

c)

x == 400

d)

x >= 400

14.

Let's say you want to repeat a shape 20 times. Which for loop would help you code that?

a)

for (var i = 1; i < 20; i++) { }

b)

for (var i = 0; i < 20; i++) { }

c)

for (var i = 0; i <= 20; i++) { }

d)

for (var i = 0; i > 20; i++) { }

15.

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?

a)

for (var x = 0; x > 400; x += 40) { }

b)

for (var x = 0; x < 400; x++) { }

c)

for (var x = 0; x < 400; x += 40) { }

d)

for (var x = 0; x > 400; x++) { }