Bird
0
0

Identify the syntax error in the following PHP code using the ternary operator:

medium📝 Debug Q6 of 15
PHP - Conditional Statements
Identify the syntax error in the following PHP code using the ternary operator:
$score = 85;
$result = $score >= 70 ? 'Pass' 'Fail';
echo $result;
AUsing single quotes instead of double quotes
BIncorrect comparison operator '>='
CMissing semicolon after echo statement
DMissing colon ':' between 'Pass' and 'Fail'
Step-by-Step Solution
Solution:
  1. Step 1: Review ternary operator syntax

    The ternary operator requires a colon ':' separating the true and false expressions.
  2. Step 2: Analyze the code

    The code misses the colon between 'Pass' and 'Fail', causing a syntax error.
  3. Final Answer:

    Missing colon ':' between 'Pass' and 'Fail' -> Option D
  4. Quick Check:

    Check for ':' after true value [OK]
Quick Trick: Ternary true and false parts must be separated by ':' [OK]
Common Mistakes:
  • Forgetting the colon ':' in ternary expressions
  • Confusing comparison operators
  • Ignoring semicolon placement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes