This example defines a function to calculate spacing by multiplying a factor by 8 pixels. Then it uses the function to set padding and margin in a container.
Hint: Use @function and @return keywords exactly [OK]
Common Mistakes:
Using 'return' instead of '@return'
Omitting the @ in @function
Confusing @function with @mixin
3. Given the Sass function:
@function add($a, $b) { @return $a + $b; }
What will be the output of this Sass code?
.result { width: add(10px, 5px); }
medium
A. .result { width: 10px 5px; }
B. .result { width: 15px; }
C. Syntax error
D. .result { width: add(10px, 5px); }
Solution
Step 1: Understand the function behavior
The function add takes two values and returns their sum using @return $a + $b;.
Step 2: Apply the function in the style
Calling add(10px, 5px) returns 15px, so the CSS becomes .result { width: 15px; }.
Final Answer:
.result { width: 15px; } -> Option B
Quick Check:
Function returns sum, so width is 15px [OK]
Hint: Functions return values, so output replaces function call [OK]
Common Mistakes:
Expecting function name to appear in output
Confusing list output with addition
Thinking it causes syntax error
4. Identify the error in this Sass function:
@function multiply($x, $y) { return $x * $y; }
medium
A. Parameters must be strings
B. Function name is invalid
C. Missing @ before return keyword
D. Function cannot have two parameters
Solution
Step 1: Check the return statement syntax
In Sass functions, the return keyword must be @return, not just return.
Step 2: Verify other parts
The function name and parameters are valid, and multiple parameters are allowed.
Final Answer:
Missing @ before return keyword -> Option C
Quick Check:
Use @return, not return [OK]
Hint: Always use @return in Sass functions [OK]
Common Mistakes:
Using 'return' without @
Thinking parameters must be strings
Believing function names can't have multiple parameters
5. You want to create a Sass function shade-color that darkens a color by a percentage. Which of these function definitions correctly uses @function and @return to achieve this?