Conditional Statements Quiz - CBSE Class 8 ICT
Free practice quiz: Conditional Statements (CBSE Class 8 ICT). 20 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This CBSE Class 8 ICT practice quiz has 20 multiple-choice questions on Conditional Statements, and 20 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 20 questions, freeSample questions
What is a conditional statement in programming?
Show answer
Answer: B. A statement that executes based on a condition
A conditional statement allows execution of certain parts of the code based on whether a condition is true or false, making it a key concept in programming.
What will the following code print? if (true) { console.log('Yes'); } else { console.log('No'); }
Show answer
Answer: A. Yes
Since the condition is 'true', the first block will execute, printing 'Yes' to the console.
What will be the output of the following code block? var a = 10; if (a == 10) { console.log('Ten'); } else { console.log('Not Ten'); }
Show answer
Answer: A. Ten
The value of a is equal to 10, so the condition is true, and 'Ten' will be printed.
What will happen if none of the if or else-if conditions are satisfied?
Show answer
Answer: C. The else block will execute if present
If all if and else-if conditions are false, the else block, if defined, will execute, allowing for a default action.
How can an 'if' statement be terminated in programming?
Show answer
Answer: D. With a curly brace }
An 'if' statement block in most programming languages is terminated by a curly brace to signify the end of the conditional block.
More questions in this quiz
Answers and explanations are in the full quiz.
- Which of the following is the correct syntax for an if statement?
- In programming, what does the else statement do?
- Which of the following statements is true about the 'if-else' structure?
- In which situation would you use a nested if statement?
- What will the following code output if x = 5? if (x > 10) { console.log('High'); } else { console.log('Low'); }
- Which operator is used to compare two values?
- What does an 'else-if' statement allow you to do?
- When might you want to use logical operators in conditional statements?
- Which of the following is an example of a logical OR operation?
- Why might you use the switch statement instead of if-else?
- What is the return type of a conditional statement?
- Which of the following is NOT a valid condition in an if statement?
- If 'x' equals 0, what will the output of the following code be? if (x) { console.log('True'); } else { console.log('False'); }
- What does a default case in a switch statement do?
- Which is a benefit of using a ternary operator?
More quizzes
Browse all Programming Basics quizzes