Challenge - 5 Problems
SASS Function Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output CSS of this SASS function?
Given the following SASS code, what is the output CSS after compilation?
SASS
@function double($n) { @return $n * 2; } .box { width: double(5rem); height: double(3rem); }
Attempts:
2 left
💡 Hint
Remember that the function returns the number multiplied by 2, so 5rem becomes 10rem.
✗ Incorrect
The function double multiplies the input by 2. So 5rem * 2 = 10rem and 3rem * 2 = 6rem. The compiled CSS uses these values.
🧠 Conceptual
intermediate2:00remaining
What error does this SASS function code produce?
Consider this SASS function code. What error will it cause when compiling?
SASS
@function add($a, $b) { $sum: $a + $b @return $sum; } .box { width: add(3rem, 2rem); }
Attempts:
2 left
💡 Hint
Check the line where $sum is assigned. Is the syntax complete?
✗ Incorrect
In SASS, each statement must end with a semicolon. The line "$sum: $a + $b" is missing a semicolon, causing a syntax error.
❓ rendering
advanced2:00remaining
What is the computed width of .container?
Given this SASS code with a function, what is the width value in the compiled CSS?
SASS
@function scale($size, $factor: 1.5) { @return $size * $factor; } .container { width: scale(4rem); }
Attempts:
2 left
💡 Hint
The function multiplies the size by the factor, which defaults to 1.5.
✗ Incorrect
The function scale multiplies 4rem by the default factor 1.5, resulting in 6rem width.
❓ selector
advanced2:00remaining
Which option correctly uses a function to set color opacity?
Which SASS code correctly defines and uses a function to return a color with 50% opacity?
Attempts:
2 left
💡 Hint
Opacity in rgba() is a number between 0 and 1, not a percentage or string.
✗ Incorrect
Option A correctly uses 0.5 as a number for 50% opacity. Option A uses 50% which is invalid, C uses 5 which is out of range, D uses a string which is invalid.
❓ accessibility
expert3:00remaining
How can a SASS function improve accessible color contrast?
Which SASS function code snippet best helps create accessible text colors by adjusting brightness for contrast?
Attempts:
2 left
💡 Hint
Mixing black with a color can darken it proportionally, helping contrast.
✗ Incorrect
Option B uses mix() with black to adjust brightness dynamically, which can improve contrast for accessibility. Lighten and darken alone may not provide consistent contrast. Saturate changes color intensity but not brightness.