Bird
0
0

You want to write a PowerShell script that prints:

hard📝 Application Q8 of 15
PowerShell - Control Flow
You want to write a PowerShell script that prints:
- 'Low' if the value is less than 50
- 'Medium' if the value is between 50 and 100 inclusive
- 'High' if the value is greater than 100
Which if-elseif-else structure correctly implements this?
Aif ($val -lt 50) { 'Low' } elseif ($val -le 100) { 'Medium' } else { 'High' }
Bif ($val -le 50) { 'Low' } elseif ($val -lt 100) { 'Medium' } else { 'High' }
Cif ($val -lt 50) { 'Low' } elseif ($val -gt 50 -and $val -le 100) { 'Medium' } else { 'High' }
Dif ($val -lt 50) { 'Low' } elseif ($val -ge 50 -and $val -le 100) { 'Medium' } else { 'High' }
Step-by-Step Solution
Solution:
  1. Step 1: Check 'Low' condition

    Value less than 50 prints 'Low'. Condition: $val -lt 50.
  2. Step 2: Check 'Medium' condition

    Value between 50 and 100 inclusive prints 'Medium'. Condition must be $val -ge 50 and $val -le 100.
  3. Step 3: Else condition

    Values greater than 100 print 'High'.
  4. Step 4: Evaluate options

    if ($val -lt 50) { 'Low' } elseif ($val -ge 50 -and $val -le 100) { 'Medium' } else { 'High' } correctly uses $val -ge 50 -and $val -le 100 for 'Medium'.
  5. Final Answer:

    Use -ge and -le for inclusive ranges -> Option D
  6. Quick Check:

    Check boundary conditions carefully [OK]
Quick Trick: Use -ge and -le for inclusive ranges [OK]
Common Mistakes:
  • Using incorrect comparison operators for ranges
  • Not including lower bound in 'Medium' condition
  • Overlapping or missing value ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes