wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

FST Class 2023- Quiz 2

Total questions: 10

Worksheet time: 11mins

Name
Class
Date
1.

What is the purpose of the `if` statement in JavaScript?

a)

To define a function

b)

To create a loop

c)

To make a decision based on a condition

d)

To declare a variable

2.

What is the syntax for an `if` statement in JavaScript?

a)

if condition { code }

b)

if (condition) { code }

c)

(condition) if { code }

d)

if { code } (condition)

3.

What is the purpose of the `else` statement in JavaScript?

a)

To define a function

b)

To create a loop

c)

To provide an alternative code block when the `if` condition is false

d)

To declare a variable

4.

What is the purpose of a nested `if-else` statement?

a)

To create complex loops

b)

To handle multiple `if` conditions

c)

To improve code readability

d)

To create a decision tree with multiple levels of conditions

5.

How do you write a nested `if-else` statement?

a)

if else { code } (condition)

b)

if (condition) else { code }

c)

if (condition) { code } else { code }

d)

if { code } else (condition) { code }

6.

Which of the following is the correct way to check if a number is both even and positive using `if-else`?

a)

if (num % 2 === 0 && num > 0)

b)

if (num % 2 === 0 || num > 0)

c)

if (num % 2 === 0 && num >= 0)

d)

if (num % 2 === 0 || num >= 0)

7.

How many conditions can be checked in a single `if-else` statement?

a)

Only one

b)

Two

c)

Multiple

d)

No limit

8.

Which of the following is a correct example of nested `if-else` statement?

a)

if (condition) { if (condition) { code } }

b)

if { if { code } (condition) } (condition)

c)

if (condition) { if { code } }

d)

(condition) if { code } else { code }

9.

What is the output of the following code?

var num = 12;

if (num > 10) {

if (num < 15) {

console.log("Between 10 and 15");

}

} else {

console.log("Not between 10 and 15");

}

a)

Between 10 and 15

b)

Not between 10 and 15

c)

Both Between 10 and 15 and Not between 10 and 15

d)

No output

10.

What is the output of the following code?

var num = -5;

if (num) {

console.log("Truthy");

} else {

console.log("Falsy");

}

a)

Truthy

b)

Falsy

c)

Both Truthy and Falsy

d)

No output