Bird
0
0

Find the error in this PHP code snippet:

medium📝 Debug Q14 of 15
PHP - Conditional Statements

Find the error in this PHP code snippet:

<?php
$age = 20;
if ($age > 18) {
    echo "Adult";
} elseif $age >= 13 {
    echo "Teenager";
} else {
    echo "Child";
}
?>
AMissing parentheses around elseif condition
BMissing semicolon after echo statements
CIncorrect variable name in elseif
DNo else block present
Step-by-Step Solution
Solution:
  1. Step 1: Review elseif syntax

    In PHP, conditions must be inside parentheses, but here elseif lacks parentheses.
  2. Step 2: Check other parts

    Echo statements have semicolons, variable names are correct, else block exists.
  3. Final Answer:

    Missing parentheses around elseif condition -> Option A
  4. Quick Check:

    Parentheses required for elseif condition [OK]
Quick Trick: Always put conditions in parentheses [OK]
Common Mistakes:
  • Forgetting parentheses in elseif
  • Confusing semicolon placement
  • Assuming else block is optional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes