0
0
SASSmarkup~20 mins

Why custom functions are useful in SASS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use custom functions in Sass?
Which of the following best explains why custom functions are useful in Sass?
AThey automatically convert Sass files into JavaScript files for better browser compatibility.
BThey allow you to reuse code by performing calculations and returning values, making stylesheets easier to maintain.
CThey replace CSS selectors with HTML tags to simplify styling.
DThey let you write CSS without any syntax rules or structure.
Attempts:
2 left
💡 Hint
Think about how functions help avoid repeating code and make styles easier to update.
📝 Syntax
intermediate
2: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);
}
ASyntaxError: Invalid function call
B
.box {
  width: double(5rem);
}
C
.box {
  width: 5rem;
}
D
.box {
  width: 10rem;
}
Attempts:
2 left
💡 Hint
The function doubles the input value.
selector
advanced
2: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');
}
A
.alert {
  background-color: #ff0000;
}
B
.alert {
  background-color: #00ff00;
}
C
.alert {
  background-color: #0000ff;
}
DSyntaxError: Invalid color value
Attempts:
2 left
💡 Hint
The function returns red for 'error' type.
layout
advanced
2: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);
}
A
.container {
  margin: 3rem;
}
B
.container {
  margin: 2rem;
}
CTypeError: Cannot multiply number by unit
D
.container {
  margin: spacing(2);
}
Attempts:
2 left
💡 Hint
Multiply 2 by 1.5rem.
accessibility
expert
2:30remaining
Using custom functions to improve accessibility
How can custom functions in Sass help improve accessibility in web design?
ABy converting all text to uppercase for better visibility.
BBy automatically adding ARIA attributes to HTML elements.
CBy calculating and returning color contrast ratios to ensure text is readable against backgrounds.
DBy disabling keyboard navigation to simplify user interaction.
Attempts:
2 left
💡 Hint
Think about how colors and contrast affect readability.