Challenge - 5 Problems
Conditional Logic 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 Bash script with conditionals?
Consider the following Bash script. What will it print when run?
Bash Scripting
count=5 if [ $count -gt 3 ]; then echo "Count is greater than 3" else echo "Count is 3 or less" fi
Attempts:
2 left
💡 Hint
Check the condition if count is greater than 3.
✗ Incorrect
The variable count is 5, which is greater than 3, so the if condition is true and the first echo runs.
💻 Command Output
intermediate2:00remaining
What output does this nested conditional produce?
What will this Bash script print?
Bash Scripting
value=10 if [ $value -lt 5 ]; then echo "Less than 5" elif [ $value -eq 10 ]; then echo "Equal to 10" else echo "Other value" fi
Attempts:
2 left
💡 Hint
Check the elif condition carefully.
✗ Incorrect
The value is 10, so the first if is false, but the elif condition is true, so it prints 'Equal to 10'.
🔧 Debug
advanced2:00remaining
Why does this Bash script fail to run?
This script is intended to print "Positive" if the number is greater than zero, but it fails. What is the error?
Bash Scripting
num=3 if [ $num -gt 0 ]; then echo "Positive" fi
Attempts:
2 left
💡 Hint
Check the operator used inside the square brackets.
✗ Incorrect
In Bash, '>' is a redirection operator, not a numeric comparison. The correct operator is '-gt'.
💻 Command Output
advanced2:00remaining
What does this script print with multiple conditions?
What is the output of this Bash script?
Bash Scripting
score=75 if [ $score -ge 90 ]; then echo "Grade A" elif [ $score -ge 80 ]; then echo "Grade B" elif [ $score -ge 70 ]; then echo "Grade C" else echo "Grade F" fi
Attempts:
2 left
💡 Hint
Check which condition matches the score first.
✗ Incorrect
Score 75 is not >= 90 or 80, but it is >= 70, so it prints 'Grade C'.
💻 Command Output
expert2:00remaining
What is the output of this Bash script using logical AND in condition?
What will this script print?
Bash Scripting
a=5 b=10 if [ $a -lt 10 ] && [ $b -gt 5 ]; then echo "Both conditions true" else echo "One or both conditions false" fi
Attempts:
2 left
💡 Hint
Both conditions must be true for the if to run.
✗ Incorrect
a=5 is less than 10 and b=10 is greater than 5, so both conditions are true and it prints 'Both conditions true'.