Complete the code to define a function named double that returns twice the input value.
@function double($number) {
@return $number [1] 2;
}
The @function keyword defines a function in Sass. To double a number, multiply it by 2 using the * operator.
Complete the code to define a function named is-even that returns true if the input number is even.
@function is-even($num) {
@return $num [1] 2 == 0;
}
The modulo operator % gives the remainder. If $num % 2 equals 0, the number is even.
Fix the error in the function that returns the square of a number.
@function square($n) {
@return $n [1] $n;
}
Sass does not support the ** or ^ operators for powers. Use * to multiply the number by itself.
Fill both blanks to create a function max-value that returns the larger of two numbers.
@function max-value($a, $b) {
@if $a [1] $b {
@return $a;
} @else {
@return $b;
}
}
The function compares two numbers. If $a is greater than $b, return $a. Otherwise, return $b.
Fill both blanks to create a function clamp that limits a number between a minimum and maximum.
@function clamp($value, $min, $max) {
@if $value [1] $min {
@return $min;
} @else if $value [2] $max {
@return $max;
} @else {
@return $value;
}
}
The function checks if $value is less than $min, returns $min. If greater than $max, returns $max. Otherwise, returns $value as is.