WorksheetsFST Class 2023- Quiz 2
Total questions: 10
Worksheet time: 11mins
What is the purpose of the `if` statement in JavaScript?
To define a function
To create a loop
To make a decision based on a condition
To declare a variable
What is the syntax for an `if` statement in JavaScript?
if condition { code }
if (condition) { code }
(condition) if { code }
if { code } (condition)
What is the purpose of the `else` statement in JavaScript?
To define a function
To create a loop
To provide an alternative code block when the `if` condition is false
To declare a variable
What is the purpose of a nested `if-else` statement?
To create complex loops
To handle multiple `if` conditions
To improve code readability
To create a decision tree with multiple levels of conditions
How do you write a nested `if-else` statement?
if else { code } (condition)
if (condition) else { code }
if (condition) { code } else { code }
if { code } else (condition) { code }
Which of the following is the correct way to check if a number is both even and positive using `if-else`?
if (num % 2 === 0 && num > 0)
if (num % 2 === 0 || num > 0)
if (num % 2 === 0 && num >= 0)
if (num % 2 === 0 || num >= 0)
How many conditions can be checked in a single `if-else` statement?
Only one
Two
Multiple
No limit
Which of the following is a correct example of nested `if-else` statement?
if (condition) { if (condition) { code } }
if { if { code } (condition) } (condition)
if (condition) { if { code } }
(condition) if { code } else { code }
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");
}
Between 10 and 15
Not between 10 and 15
Both Between 10 and 15 and Not between 10 and 15
No output
What is the output of the following code?
var num = -5;
if (num) {
console.log("Truthy");
} else {
console.log("Falsy");
}
Truthy
Falsy
Both Truthy and Falsy
No output
