Challenge - 5 Problems
Sass Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Why use custom functions in Sass?
Which of the following best explains why custom functions are useful in Sass?
Attempts:
2 left
💡 Hint
Think about how functions help avoid repeating code and make styles easier to update.
✗ Incorrect
Custom functions in Sass let you write reusable code blocks that perform calculations or return values. This helps keep your stylesheets clean and easier to maintain.
📝 Syntax
intermediate2:00remaining
Output of a Sass custom function
What is the output CSS of this Sass code using a custom function?
@function double($n) {
@return $n * 2;
}
.box {
width: double(5rem);
}
SASS
@function double($n) { @return $n * 2; } .box { width: double(5rem); }
Attempts:
2 left
💡 Hint
The function doubles the input value.
✗ Incorrect
The custom function double multiplies the input by 2. So, double(5rem) becomes 10rem in the compiled CSS.
❓ selector
advanced2:00remaining
Using custom functions with selectors
Consider this Sass code with a custom function that returns a color. What color will the
.alert background be in the compiled CSS?
@function alert-color($type) {
@if $type == 'error' {
@return #ff0000;
} @else if $type == 'success' {
@return #00ff00;
} @else {
@return #0000ff;
}
}
.alert {
background-color: alert-color('error');
}SASS
@function alert-color($type) { @if $type == 'error' { @return #ff0000; } @else if $type == 'success' { @return #00ff00; } @else { @return #0000ff; } } .alert { background-color: alert-color('error'); }
Attempts:
2 left
💡 Hint
The function returns red for 'error' type.
✗ Incorrect
The function checks the input string and returns #ff0000 for 'error'. So the background color is red.
❓ layout
advanced2:00remaining
Custom function impact on layout values
Given this Sass code, what will be the margin value in the compiled CSS?
@function spacing($factor) {
@return $factor * 1.5rem;
}
.container {
margin: spacing(2);
}
SASS
@function spacing($factor) { @return $factor * 1.5rem; } .container { margin: spacing(2); }
Attempts:
2 left
💡 Hint
Multiply 2 by 1.5rem.
✗ Incorrect
The function multiplies 2 by 1.5rem, resulting in 3rem margin in CSS.
❓ accessibility
expert2:30remaining
Using custom functions to improve accessibility
How can custom functions in Sass help improve accessibility in web design?
Attempts:
2 left
💡 Hint
Think about how colors and contrast affect readability.
✗ Incorrect
Custom functions can calculate color contrast ratios, helping designers pick colors that meet accessibility standards for readability.