Challenge - 5 Problems
Control Flow Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell script with if-else?
Look at this script and tell what it prints when $value is 5.
PowerShell
$value = 5 if ($value -gt 10) { Write-Output "Greater than 10" } else { Write-Output "10 or less" }
Attempts:
2 left
💡 Hint
Think about whether 5 is greater than 10 or not.
✗ Incorrect
The if condition checks if $value is greater than 10. Since 5 is not, the else block runs, printing '10 or less'.
🧠 Conceptual
intermediate2:00remaining
Why does the script skip the else block here?
Given this script, why does it print "Inside if" and skip the else block?
PowerShell
$x = 20 if ($x -eq 20) { Write-Output "Inside if" } else { Write-Output "Inside else" }
Attempts:
2 left
💡 Hint
Check the condition inside the if statement.
✗ Incorrect
The if condition checks if $x equals 20. Since it does, the if block runs and the else block is skipped.
📝 Syntax
advanced2:00remaining
Which option correctly uses a switch statement to print 'Fruit' for apple and banana?
Choose the correct PowerShell switch syntax that prints 'Fruit' when the input is 'apple' or 'banana'.
PowerShell
switch ($item) {
'apple' { Write-Output 'Fruit' }
'banana' { Write-Output 'Fruit' }
default { Write-Output 'Unknown' }
}Attempts:
2 left
💡 Hint
PowerShell switch uses braces {} for code blocks, not arrows or colons.
✗ Incorrect
Option B uses the correct PowerShell switch syntax with braces and Write-Output inside each case block.
🔧 Debug
advanced2:00remaining
What error does this script produce and why?
This script tries to use a while loop but has a mistake. What error will it produce?
PowerShell
$count = 3 while $count -gt 0 { Write-Output $count $count-- }
Attempts:
2 left
💡 Hint
Check how the while condition is written in PowerShell.
✗ Incorrect
PowerShell requires the while condition to be inside parentheses. Missing parentheses cause a syntax error.
🚀 Application
expert2:00remaining
How many times does this nested loop print 'Looping'?
Count how many times 'Looping' is printed by this script.
PowerShell
$outer = 2 $inner = 3 for ($i = 0; $i -lt $outer; $i++) { for ($j = 0; $j -lt $inner; $j++) { Write-Output 'Looping' } }
Attempts:
2 left
💡 Hint
Multiply the number of outer loop runs by inner loop runs.
✗ Incorrect
The outer loop runs 2 times, inner loop runs 3 times each. Total prints = 2 * 3 = 6.