Bird
0
0

You want to print "Adult" if age is 18 or more, otherwise "Minor". Which code correctly uses if statement execution flow?

hard📝 Application Q8 of 15
PHP - Conditional Statements
You want to print "Adult" if age is 18 or more, otherwise "Minor". Which code correctly uses if statement execution flow?
Aif $age >= 18 echo 'Adult'; else echo 'Minor';
Bif ($age >= 18) echo 'Minor'; else echo 'Adult';
Cif ($age > 18) echo 'Adult'; else echo 'Minor';
Dif ($age >= 18) { echo 'Adult'; } else { echo 'Minor'; }
Step-by-Step Solution
Solution:
  1. Step 1: Check condition and output correctness

    The condition must be age >= 18 to print 'Adult'. if ($age >= 18) { echo 'Adult'; } else { echo 'Minor'; } matches this exactly.
  2. Step 2: Verify syntax correctness

    if ($age >= 18) { echo 'Adult'; } else { echo 'Minor'; } uses parentheses and braces correctly for if-else blocks.
  3. Final Answer:

    if ($age >= 18) { echo 'Adult'; } else { echo 'Minor'; } -> Option D
  4. Quick Check:

    Correct condition and syntax = if ($age >= 18) { echo 'Adult'; } else { echo 'Minor'; } [OK]
Quick Trick: Use >= for age check and braces for clarity [OK]
Common Mistakes:
  • Using > instead of >= causing wrong output
  • Omitting parentheses or braces causing syntax errors
  • Swapping outputs in if and else blocks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes