Bird
0
0

Identify the error in this PowerShell ternary expression:

medium📝 Debug Q6 of 15
PowerShell - Operators
Identify the error in this PowerShell ternary expression:
$x = 5
$result = $x -gt 3 ? 'High' 'Low'
ATernary operator not supported in PowerShell 7+
BUsing -gt instead of > for comparison
CIncorrect variable assignment syntax
DMissing colon ':' between true and false values
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 missing colon

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

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

    Colon required between values = Missing colon ':' between true and false values [OK]
Quick Trick: Always put ':' between true and false parts [OK]
Common Mistakes:
  • Omitting colon ':'
  • Using > instead of -gt (valid but less idiomatic)
  • Thinking ternary unsupported in PowerShell 7+

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes