Recall & Review
beginner
What is the purpose of an
if statement in JavaScript?An
if statement lets the program decide to run some code only if a condition is true. It helps the program make choices.Click to reveal answer
beginner
Write the basic syntax of an
if statement in JavaScript.The basic syntax is:<br>
if (condition) {<br> // code to run if condition is true<br>}Click to reveal answer
beginner
What happens if the condition in an
if statement is false?If the condition is false, the code inside the
if block does not run. The program skips it and continues.Click to reveal answer
beginner
How do you add an alternative action if the
if condition is false?You use an
else block after the if block. It runs when the if condition is false.<br>if (condition) {<br> // runs if true<br>} else {<br> // runs if false<br>}Click to reveal answer
intermediate
Can you check multiple conditions with
if statements? How?Yes, by using
else if blocks between if and else. It checks conditions one by one until one is true.<br>if (cond1) {<br> // code<br>} else if (cond2) {<br> // code<br>} else {<br> // code<br>}Click to reveal answer
What does this code do?<br>
if (5 > 3) { console.log('Yes'); }✗ Incorrect
5 is greater than 3, so the condition is true and 'Yes' is printed.
Which keyword runs code when the
if condition is false?✗ Incorrect
The
else block runs when the if condition is false.What will this code print?<br>
if (false) { console.log('A'); } else { console.log('B'); }✗ Incorrect
The condition is false, so the
else block runs and prints 'B'.How do you check more than two conditions in an
if statement?✗ Incorrect
You use
else if blocks to check multiple conditions one after another.What is the output of:<br>
if (10 === '10') { console.log('Match'); } else { console.log('No match'); }✗ Incorrect
The triple equals
=== checks type and value. Number 10 is not the same type as string '10', so condition is false.Explain how an
if statement works in JavaScript and give a simple example.Think about how you decide to do something only if a condition is true.
You got /4 concepts.
Describe how to use
else if and else to handle multiple choices in JavaScript.Imagine choosing between many options, checking one by one.
You got /4 concepts.