Bird
Raised Fist0
SASSmarkup~20 mins

@return statement in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sass Return Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the output of this Sass function?
Consider the following Sass function that uses @return. What will be the value of $result after compilation?
SASS
@function double($n) {
  @return $n * 2;
}

$result: double(5);
A25
B5
C10
DError: Undefined variable
Attempts:
2 left
💡 Hint
The function returns the input number multiplied by 2.
🧠 Conceptual
intermediate
2:00remaining
What happens if a Sass function has no @return statement?
In Sass, what is the result when a function does not include an @return statement?
SASS
@function noReturn() {
  $x: 5;
  // no return here
}

$value: noReturn();
ACompilation error: missing @return statement.
BThe function returns 0 by default.
CThe function returns the last variable assigned, $x (5).
DThe function returns null, so $value is null.
Attempts:
2 left
💡 Hint
Sass functions must explicitly return a value with @return.
❓ rendering
advanced
2:00remaining
What color will the text be after Sass compilation?
Given this Sass code using a function with @return, what color will the paragraph text have in the browser?
SASS
@function theme-color($mode) {
  @if $mode == light {
    @return #333333;
  } @else if $mode == dark {
    @return #eeeeee;
  } @else {
    @return #000000;
  }
}

p {
  color: theme-color(dark);
}
AThe text color will be transparent.
BThe text color will be #eeeeee (light gray).
CThe text color will be #000000 (black).
DThe text color will be #333333 (dark gray).
Attempts:
2 left
💡 Hint
Check which color is returned when the mode is 'dark'.
❓ selector
advanced
2:00remaining
Which Sass function call returns a list with three items?
Given the Sass function below, which call returns a list with exactly three items?
SASS
@function create-list($a, $b, $c) {
  @return ($a, $b, $c);
}
Acreate-list(1, 2, 3)
Bcreate-list(1, 2)
Ccreate-list(1)
Dcreate-list()
Attempts:
2 left
💡 Hint
The function returns a list of the three parameters passed.
❓ accessibility
expert
3:00remaining
How can you use Sass functions with @return to improve accessible color contrast?
You want to create a Sass function that returns a text color based on background brightness to ensure good contrast for accessibility. Which function correctly uses @return to achieve this?
A
@function accessible-text-color($bg) {
  @if lightness($bg) > 50% {
    @return #000000;
  } @else {
    @return #ffffff;
  }
}
B
@function accessible-text-color($bg) {
  @if lightness($bg) > 50% {
    #000000;
  } @else {
    @return #ffffff;
  }
}
C
@function accessible-text-color($bg) {
  @if lightness($bg) < 50% {
    @return #000000;
  } @else {
    #ffffff;
  }
}
D
@function accessible-text-color($bg) {
  @return if(lightness($bg) > 50%, #000000, #ffffff);
}
Attempts:
2 left
💡 Hint
Make sure every path in the function uses @return to send back a color.

Practice

(1/5)
1. What does the @return statement do in Sass?
easy
A. It sends a value back from a Sass function.
B. It creates a new CSS rule.
C. It imports another Sass file.
D. It defines a variable.

Solution

  1. Step 1: Understand the purpose of @return

    The @return statement is used inside a Sass function to send a value back to where the function was called.
  2. Step 2: Differentiate from other Sass features

    Other options describe different Sass features: creating CSS rules, importing files, or defining variables, which are not the role of @return.
  3. Final Answer:

    It sends a value back from a Sass function. -> Option A
  4. Quick Check:

    @return sends value back [OK]
Hint: Remember: @return always sends a value back [OK]
Common Mistakes:
  • Thinking @return creates CSS rules
  • Confusing @return with variable declaration
  • Using @return outside a function
2. Which of the following is the correct syntax to return a value from a Sass function named double that doubles a number $n?
easy
A. @function double($n) { @output $n * 2; }
B. @function double($n) { return $n * 2; }
C. @function double($n) { $n * 2; }
D. @function double($n) { @return $n * 2; }

Solution

  1. Step 1: Identify correct Sass function syntax

    In Sass, functions start with @function and use @return to send back a value.
  2. Step 2: Check each option for correct usage

    @function double($n) { @return $n * 2; } uses @return correctly. @function double($n) { return $n * 2; } misses the @ before return. @function double($n) { $n * 2; } lacks any return statement. @function double($n) { @output $n * 2; } uses an invalid @output keyword.
  3. Final Answer:

    @function double($n) { @return $n * 2; } -> Option D
  4. Quick Check:

    Use @return inside @function [OK]
Hint: Always use @return with @function [OK]
Common Mistakes:
  • Omitting the '@' before return
  • Forgetting to include a return statement
  • Using invalid keywords like '@output'
3. What will be the output CSS of the following Sass code?
@function triple($x) {
  @return $x * 3;
}

.box {
  width: triple(10px);
}
medium
A. .box { width: 30px; }
B. .box { width: triple(10px); }
C. .box { width: 10px; }
D. Syntax error

Solution

  1. Step 1: Understand the function behavior

    The function triple multiplies the input by 3 and returns the result.
  2. Step 2: Calculate the returned value

    Calling triple(10px) returns 10px * 3 = 30px. This value is assigned to the width property.
  3. Final Answer:

    .box { width: 30px; } -> Option A
  4. 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

  1. 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.
  2. 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.
  3. Final Answer:

    Missing @return statement to send back the result. -> Option C
  4. 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?
hard
A. @function adjust-color-brightness($color, $percent) { return if($percent > 0, lighten($color, $percent), darken($color, abs($percent))); }
B. @function adjust-color-brightness($color, $percent) { @if $percent > 0 { @return lighten($color, $percent); } @else { @return darken($color, abs($percent)); } }
C. @function adjust-color-brightness($color, $percent) { lighten($color, $percent); darken($color, abs($percent)); }
D. @function adjust-color-brightness($color, $percent) { @return lighten($color, $percent); @return darken($color, abs($percent)); }

Solution

  1. Step 1: Understand conditional return usage

    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.
  2. 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.
  3. Final Answer:

    @function adjust-color-brightness($color, $percent) { @if $percent > 0 { @return lighten($color, $percent); } @else { @return darken($color, abs($percent)); } } -> Option B
  4. Quick Check:

    Use conditional @return for multiple outcomes [OK]
Hint: Use one @return per condition inside functions [OK]
Common Mistakes:
  • Placing multiple @return statements without conditions
  • Not returning any value
  • Using function calls without returning them
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard