Challenge - 5 Problems
Integer Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of integer arithmetic in Bash
What is the output of this Bash script?
Bash Scripting
a=5 b=3 c=$((a + b * 2)) echo $c
Attempts:
2 left
💡 Hint
Remember that multiplication has higher precedence than addition.
✗ Incorrect
In Bash arithmetic, multiplication happens before addition. So b * 2 = 6, then a + 6 = 11.
📝 Syntax
intermediate2:00remaining
Correct integer assignment in Bash
Which option correctly assigns the integer value 10 to variable x in Bash?
Attempts:
2 left
💡 Hint
In Bash, assignment does not use spaces around = and no extra symbols.
✗ Incorrect
Bash assigns variables with no spaces around =. 'x=10' is correct. 'let' is for arithmetic evaluation, not assignment. ':=' and '==' are invalid here.
🔧 Debug
advanced2:00remaining
Why does this Bash script fail to add integers?
Given this script:
x=5
y=3
z=$x + $y
echo $z
What is the output and why?
Bash Scripting
x=5 y=3 z="$x + $y" echo $z
Attempts:
2 left
💡 Hint
Check how arithmetic is done in Bash and how variables are expanded.
✗ Incorrect
The expression '$x + $y' is treated as a string, not arithmetic. So z becomes '5 + 3'. To do arithmetic, use $((x + y)).
🚀 Application
advanced3:00remaining
Calculate factorial using integer variables in Bash
Which script correctly calculates factorial of 4 and prints the result?
Attempts:
2 left
💡 Hint
Check the loop syntax and arithmetic operation used for factorial.
✗ Incorrect
Option B uses correct C-style for loop and multiplies fact by i each iteration. B fails because {1..n} does not expand n variable. A counts down but is correct factorial logic, but n is modified so loop ends correctly. D adds instead of multiplies.
🧠 Conceptual
expert2:00remaining
Integer variable behavior in Bash with arithmetic expansion
Consider this Bash snippet:
x=10
y=3
z=$((x / y))
echo $z
What is the output and why?
Attempts:
2 left
💡 Hint
Bash arithmetic expansion works with integers only.
✗ Incorrect
Bash integer arithmetic truncates results, so 10 / 3 equals 3, not 3.3333 or 4. Bash does not support floating point in $(( )).