Bird
0
0

Find the error in this PHP code using ternary operator:

medium📝 Debug Q14 of 15
PHP - Conditional Statements
Find the error in this PHP code using ternary operator:
$score = 75;
$grade = $score > 60 ? 'Pass' 'Fail';
echo $grade;
AWrong variable name used
BMissing colon ':' between true and false values
CTernary operator cannot be used with strings
DMissing semicolon after echo
Step-by-Step Solution
Solution:
  1. Step 1: Check ternary operator syntax

    The ternary operator requires a colon ':' between the true and false values.
  2. Step 2: Identify the missing colon

    Code has 'Pass' 'Fail' without ':' causing syntax error.
  3. Final Answer:

    Missing colon ':' between true and false values -> Option B
  4. Quick Check:

    Syntax needs ? true : false [OK]
Quick Trick: Always put ':' between true and false parts [OK]
Common Mistakes:
  • Omitting colon ':'
  • Using comma instead of colon
  • Confusing variable names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes