wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

switch case

Total questions: 17

Worksheet time: 9mins

Name
Class
Date
1.

By the ? keyword, the other cases will not be executed and the program continues executing the code after the switch case if there is more code.

Which is the "?" keyword?

(a)  

2.

What is the keyword that we use, when we want to have different cases based on the expression's value?

a)

switch

b)

Switch

c)

if

d)

default

3.

Can I make a switch case without inserting code to be executed in the default case?

a)

No

b)

Yes

4.

Can you use if case instead of switch case?

a)

Yes

b)

No

5.

Is that correct?

switch (number < 10) ...

a)

Yes

b)

No

6.

Choose the correct answer

a)

case "cat":

b)

case: cat

c)

case: "cat"

d)

case cat:

7.

Is that correct "case 5:"?

a)

Yes

b)

No

8.

Is that correct?

case "s":

a)

Yes

b)

No

9.

Select the correct option :


The switch expression is evaluated ____________

a)

once

b)

twice

c)

every time the condition is checked

10.

Select the correct option :


The _____ in switch statement is used to terminate the execution of the rest of the code in the switch block.

a)

default

b)

case

c)

break

11.

State True or False :


The default statement is compulsory and it can be used anywhere inside the switch statement.

a)

True

b)

False

12.

State True or False :


It is not necessary to break the last case in a switch block.

a)

True

b)

False

13.

Select the correct option:


Switch case is a __________ statement.

a)

default

b)

loop

c)

break

d)

conditional

14.

Select the correct option:


_______________ is a situation that occurs when we miss out break statement with switch cases.

a)

Fall through

b)

Default

c)

Desired output

d)

No output

15.

Select the correct option :


Switch case uses _______________ to match value and type.

a)

comparison

b)

==

c)

strict comparison

d)

<and>

16.

Select the correct output for following code snippet :


var d=1, e=2,g=3,i=1;

switch(i)

{

case 1 : d=d+1;

case 2 : e=e+1;

case 3 : g=g+1;

}

document.write(d+ " " + e+ " " +g);

a)

2

b)

234

c)

2 3 4

d)

No output

17.

The user is not getting any output. Select the line which has error :


var fruit = "apples" - Line 1

switch(fruit) - Line 2

case "grapes" : - Line 3

document.write("Green or black?"); - Line 4

break; - Line 5

case "apples" : - Line 6

document.write("Red are the best") - Line 7

break; - Line 8

default : - Line 9

document.write("Enter apples or grapes "); - Line 10

} - Line 11

a)

Line 1

b)

Line 3

c)

Line 7

d)

Line 11