This example shows a custom function spacing that multiplies a number by 1.5rem. We use it to set padding and margin in a container. This keeps spacing consistent and easy to change.
The function double multiplies the input by 2, so double(10px) returns 20px.
Step 2: Check the compiled CSS output
The Sass compiler replaces the function call with the returned value, so the margin becomes 20px.
Final Answer:
.box { margin: 20px; } -> Option D
Quick Check:
Function doubles 10px to 20px [OK]
Hint: Custom functions return values replacing calls in CSS [OK]
Common Mistakes:
Expecting function name to appear in CSS
Thinking Sass functions run in browser
Confusing input and output units
4. Identify the error in this Sass custom function:
@function add($a, $b) { return $a + $b; }
medium
A. Using 'return' instead of '@return' causes error
B. Function name cannot be 'add'
C. Missing @return keyword inside the function
D. Parameters must be declared without $
Solution
Step 1: Check Sass function syntax
Sass requires @return keyword to return values, not plain return.
Step 2: Identify the error
Using return without @ causes a syntax error in Sass.
Final Answer:
Using 'return' instead of '@return' causes error -> Option A
Quick Check:
@return required, not return [OK]
Hint: Use @return, not return, inside Sass functions [OK]
Common Mistakes:
Writing 'return' without @ in Sass
Thinking function names are restricted
Omitting $ in parameter names
5. You want to create a custom function in Sass that returns a color with adjusted opacity. Which approach best uses custom functions to keep your design consistent?
hard
A. Use JavaScript to change opacity after the page loads.
B. Write the rgba color manually every time you need opacity.
C. Define a function that takes a color and opacity, then returns the color with that opacity applied.
D. Create multiple CSS classes for each opacity level.
Solution
Step 1: Understand the goal of consistency and reuse
Using a custom function to adjust opacity means you write the logic once and reuse it everywhere.
Step 2: Compare options for maintainability
Manually writing rgba or using JS or many classes is less maintainable and less consistent than a function.
Final Answer:
Define a function that takes a color and opacity, then returns the color with that opacity applied. -> Option C
Quick Check:
Custom function for opacity = consistent design [OK]
Hint: Use functions to apply opacity consistently [OK]
Common Mistakes:
Hardcoding colors repeatedly
Relying on JavaScript for style changes
Creating many CSS classes instead of functions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.