Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q13 of 15
PHP - Conditional Statements

What will be the output of this PHP code?

<?php
$score = 75;
if ($score >= 90) {
    echo "Grade A";
} elseif ($score >= 80) {
    echo "Grade B";
} elseif ($score >= 70) {
    echo "Grade C";
} else {
    echo "Grade F";
}
?>
AGrade A
BGrade F
CGrade B
DGrade C
Step-by-Step Solution
Solution:
  1. Step 1: Check conditions in order

    Score is 75. First condition (>=90) is false, second (>=80) false, third (>=70) true.
  2. Step 2: Determine executed block

    Since third condition is true, it prints "Grade C" and skips else.
  3. Final Answer:

    Grade C -> Option D
  4. Quick Check:

    75 >= 70 = Grade C [OK]
Quick Trick: Check conditions top to bottom, first true runs [OK]
Common Mistakes:
  • Choosing Grade B or A incorrectly
  • Ignoring elseif order
  • Assuming else runs always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes