Bird
0
0

You want to write a script that prints:

hard📝 Application Q15 of 15
PowerShell - Control Flow
You want to write a script that prints:
- 'Cold' if temperature is below 10,
- 'Warm' if temperature is between 10 and 25 inclusive,
- 'Hot' if temperature is above 25.
Which if-elseif-else structure correctly implements this?
Aif ($temp -lt 10) { 'Cold' } elseif ($temp -ge 25) { 'Hot' } else { 'Warm' }
Bif ($temp -le 10) { 'Cold' } elseif ($temp -lt 25) { 'Warm' } else { 'Hot' }
Cif ($temp -lt 10) { 'Cold' } elseif ($temp -le 25) { 'Warm' } else { 'Hot' }
Dif ($temp -gt 25) { 'Hot' } elseif ($temp -gt 10) { 'Warm' } else { 'Cold' }
Step-by-Step Solution
Solution:
  1. Step 1: Analyze temperature ranges and verify conditions

    Cold: below 10, Warm: 10-25 inclusive, Hot: above 25. "if ($temp -lt 10) { 'Cold' } elseif ($temp -le 25) { 'Warm' } else { 'Hot' }": <10=Cold, <=25=Warm (10-25), else Hot. Matches exactly.
  2. Final Answer:

    if ($temp -lt 10) { 'Cold' } elseif ($temp -le 25) { 'Warm' } else { 'Hot' } -> Option C
  3. Quick Check:

    Ranges covered correctly = C [OK]
Quick Trick: Order conditions from smallest to largest range [OK]
Common Mistakes:
  • Mixing up less than and less or equal
  • Wrong order causing wrong output
  • Overlapping or missing ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes