The function triple multiplies the input by 3 and returns the result.
Step 2: Calculate the returned value
Calling triple(10px) returns 10px * 3 = 30px. This value is assigned to the width property.
Final Answer:
.box { width: 30px; } -> Option A
Quick Check:
Function returns 3 times input [OK]
Hint: Multiply input inside function, output is computed value [OK]
Common Mistakes:
Expecting the function name to appear in CSS
Ignoring units like px in calculations
Assuming no multiplication happens
4. Identify the error in this Sass function:
@function add($a, $b) {
$sum: $a + $b;
}
medium
A. Cannot use addition inside functions.
B. Incorrect variable declaration syntax.
C. Missing @return statement to send back the result.
D. Function name should start with a dollar sign.
Solution
Step 1: Check function body for return statement
The function calculates $sum but never returns it. Sass functions must use @return to send a value back.
Step 2: Verify other syntax elements
Variable declaration and addition are correct. Function names do not start with a dollar sign. Addition is allowed inside functions.
Final Answer:
Missing @return statement to send back the result. -> Option C
Quick Check:
Functions need @return [OK]
Hint: Always end functions with @return [OK]
Common Mistakes:
Forgetting to return the calculated value
Thinking function names need $ prefix
Assuming calculations auto-return
5. You want to create a Sass function adjust-color-brightness that takes a color and a percentage, then returns the color lightened or darkened by that percentage. Which of these is the best way to use @return inside this function?
The function should return either a lightened or darkened color based on the sign of $percent. Using @if with separate @return statements is clear and correct.
Step 2: Evaluate other options
@function adjust-color-brightness($color, $percent) {
return if($percent > 0, lighten($color, $percent), darken($color, abs($percent)));
} uses return without @, which is invalid Sass syntax. @function adjust-color-brightness($color, $percent) {
lighten($color, $percent);
darken($color, abs($percent));
} lacks any @return, so no value is returned. @function adjust-color-brightness($color, $percent) {
@return lighten($color, $percent);
@return darken($color, abs($percent));
} has two @return statements in sequence, which is invalid because only one @return can be executed.