Bird
0
0

Identify the problem in this PHP code:

medium📝 Debug Q7 of 15
PHP - Conditional Statements

Identify the problem in this PHP code:

<?php
$value = 15;
if ($value > 20) {
    echo "High";
} elseif ($value > 10) 
    echo "Medium";
else {
    echo "Low";
}
ASemicolon missing after echo statements
BMissing braces {} for elseif block
CVariable $value is not initialized
DIncorrect else keyword usage
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of elseif block

    The elseif block lacks braces {}, which is allowed only if the block has one statement but can cause confusion.
  2. Step 2: Identify best practice and error potential

    Missing braces can cause errors if more statements are added; best to always use braces.
  3. Final Answer:

    Missing braces {} for elseif block -> Option B
  4. Quick Check:

    Always use braces for clarity in elseif blocks [OK]
Quick Trick: Use braces {} for all blocks to avoid errors [OK]
Common Mistakes:
  • Skipping braces in elseif
  • Misplacing else keyword
  • Assuming variable is undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes