Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is the purpose of an if statement in JavaScript?

View

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

View

What does the following code output?

View

How many else if statements can you have in an if-else construct?

View

What will the following code output?

View

What is the purpose of the else statement?

View

What will this code print?

View

What is wrong with this code?

View

What does this code print?

View

What happens when you use an if-else statement without an else?

View

What is the purpose of an if statement in JavaScript?

To execute code if a condition is false
To execute code if a condition is true
To create a loop
To stop the program

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

if condition { }
if (condition) { }
if {condition} [ ]
if condition: { }

What does the following code output?

let x = 5; if (x > 3) { console.log("Greater than 3"); } else { console.log("Less than or equal to 3"); }

"Less than or equal to 3"
"Greater than 3"
No output
Syntax error

How many else if statements can you have in an if-else construct?

One
Two
Unlimited
None Answer

What will the following code output?

let y = 10; if (y === 5) { console.log("y is 5"); } else if (y > 5) { console.log("y is greater than 5"); } else { console.log("y is less than 5"); }

"y is 5"
"y is greater than 5"
"y is less than 5"
No output

What is the purpose of the else statement?

To execute if the if statement is true
To execute if none of the previous conditions are true
To stop the loop
To check a second condition

What will this code print?

let a = 7; if (a > 10) { console.log("Greater than 10"); } else if (a === 7) { console.log("Equal to 7"); } else { console.log("Less than 7"); }

"Greater than 10"
"Equal to 7"
"Less than 7"
No output

What is wrong with this code?

let b = 4; if b === 4 { console.log("b is 4"); }

b should be declared inside the if block
=== should be replaced with ==
The condition should be inside parentheses ()
console.log should be outside the if block

What does this code print?

let c = 15; if (c < 10) { console.log("Less than 10"); } else { console.log("10 or greater"); }

"Less than 10"
"10 or greater"
No output
Syntax error

What happens when you use an if-else statement without an else?

The code will always execute the if block
The code will not run
The program will throw an error
The else is optional and the code still works as expected