Bird
Raised Fist0
SASSmarkup~20 mins

Built-in string functions in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sass String 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 code using string functions?
Consider the following Sass code snippet. What will be the value of $result after compilation?
SASS
$text: "Hello World";
$result: str-insert($text, "-", 6);
A"Hello- World"
B"Hello World-"
C"-Hello World"
D"Hello World"
Attempts:
2 left
💡 Hint
The str-insert function inserts a string at a specific index.
🧠 Conceptual
intermediate
1:30remaining
Which Sass function returns the length of a string?
You want to find out how many characters are in a string variable in Sass. Which function should you use?
Astr-length()
Blength()
Cstring-length()
Dcount()
Attempts:
2 left
💡 Hint
The function name starts with 'str-' and relates to length.
❓ selector
advanced
2:00remaining
What error occurs when using str-slice with invalid indexes?
Given the Sass code str-slice("Sass", 5, 10), what happens?
A"s"
B"" (empty string)
CError: Invalid index
D"Sass"
Attempts:
2 left
💡 Hint
If the start index is beyond the string length, what does str-slice return?
❓ rendering
advanced
2:30remaining
What is the output color of this Sass code using string functions?
This Sass code uses string functions to create a color variable. What color will be rendered in the browser?
SASS
$hex: "#1a2b3c";
$color: unquote($hex);
body { background-color: $color; }
ABackground color is #1a2b3c (bright red)
BCompilation error due to unquote usage
CBackground color is transparent
DBackground color is #1a2b3c (a dark blue-gray)
Attempts:
2 left
💡 Hint
The unquote function removes quotes so the color is valid CSS.
❓ accessibility
expert
3:00remaining
How can you use Sass string functions to improve accessibility in CSS content?
You want to add dynamic content with a screen reader label using Sass string functions. Which approach correctly combines strings for accessibility?
SASS
$label: "Close button";
$aria: "aria-label='" + $label + "'";
.button::after { content: $aria; }
AUse unquote: content: unquote("aria-label='" + $label + "'");
BUse str-insert to add quotes: content: str-insert($aria, '"', 1);
CUse interpolation: content: "#{"aria-label='" + $label + "'"}";
DUse str-length to set content length: content: str-length($aria);
Attempts:
2 left
💡 Hint
Sass interpolation helps combine strings inside content property correctly.

Practice

(1/5)
1. Which Sass built-in string function returns the length of a string?
length("hello")
easy
A. Returns the string in uppercase
B. Returns the number of characters in the string
C. Returns the string reversed
D. Returns the first character of the string

Solution

  1. Step 1: Understand the length() function

    The length() function in Sass returns how many characters are in a string.
  2. Step 2: Apply to the example string

    For the string "hello", the length is 5 characters.
  3. Final Answer:

    Returns the number of characters in the string -> Option B
  4. Quick Check:

    length("hello") = 5 [OK]
Hint: Remember length() counts characters in a string [OK]
Common Mistakes:
  • Confusing length() with uppercase conversion
  • Thinking length() returns the first character
  • Mixing length() with reverse functions
2. Which of the following is the correct syntax to convert a string to uppercase in Sass?
easy
A. uppercase("text")
B. to-upper-case("text")
C. toUpperCase("text")
D. to-upper("text")

Solution

  1. Step 1: Recall Sass string uppercase function

    The correct Sass function to convert a string to uppercase is uppercase().
  2. Step 2: Check syntax correctness

    The function is called as uppercase("text"), which matches uppercase("text").
  3. Final Answer:

    uppercase("text") -> Option A
  4. Quick Check:

    uppercase("text") converts to "TEXT" [OK]
Hint: Use uppercase() exactly as shown for capital letters [OK]
Common Mistakes:
  • Using camelCase like toUpperCase() which is not Sass syntax
  • Adding dashes incorrectly in function names
  • Confusing with CSS text-transform property
3. What is the output of this Sass code?
$str: "Sass";
$result: str-insert($str, "3", 3);
What is the value of $result?
medium
A. "Sass3"
B. "Sas3s"
C. "S3ass"
D. "Sa3ss"

Solution

  1. Step 1: Understand str-insert() function

    This function inserts a string into another string at a given index (1-based).
  2. Step 2: Apply insertion at position 3

    Original string is "Sass". Insert "3" at position 3 means after the second character: "Sa" + "3" + "ss" = "Sa3ss".
  3. Final Answer:

    "Sa3ss" -> Option D
  4. Quick Check:

    str-insert("Sass", "3", 3) = "Sa3ss" [OK]
Hint: Remember str-insert uses 1-based index for insertion [OK]
Common Mistakes:
  • Using 0-based index instead of 1-based
  • Inserting at wrong position
  • Confusing str-insert with str-slice
4. Identify the error in this Sass code:
$text: "Hello";
$new-text: str-slice($text, 2, 1);
medium
A. Start index is greater than end index, causing empty string
B. str-slice requires three arguments, missing one
C. Variable names must start with uppercase letters
D. Strings cannot be sliced in Sass

Solution

  1. Step 1: Check str-slice() parameters

    The function takes a string, a start index, and an optional end index. Here start=2, end=1.
  2. Step 2: Analyze index order

    Since start index (2) is greater than end index (1), the slice returns an empty string, which is likely unintended.
  3. Final Answer:

    Start index is greater than end index, causing empty string -> Option A
  4. Quick Check:

    str-slice("Hello", 2, 1) = "" (empty) [OK]
Hint: Ensure start index ≤ end index in str-slice() [OK]
Common Mistakes:
  • Assuming str-slice needs three arguments always
  • Thinking variable names must be uppercase
  • Believing strings can't be sliced in Sass
5. You want to create a Sass function that returns the first three characters of a string in uppercase. Which code correctly achieves this?
hard
A. @function first-three-uppercase($str) { @return str-insert(uppercase($str), 3, 1); }
B. @function first-three-uppercase($str) { @return uppercase(str-slice($str, 1)); }
C. @function first-three-uppercase($str) { @return str-slice(uppercase($str), 1, 3); }
D. @function first-three-uppercase($str) { @return uppercase(str-insert($str, 3, 1)); }

Solution

  1. Step 1: Understand the goal

    We want the first three characters of the string in uppercase: uppercase first, then slice precisely.
  2. Step 2: Analyze each option

    @function first-three-uppercase($str) { @return str-slice(uppercase($str), 1, 3); } uppercases whole string, then slices first 3 characters -- correct.
    @function first-three-uppercase($str) { @return uppercase(str-slice($str, 1)); } str-slice from 1 to end (no end index), uppercases entire string -- incorrect, too many chars.
    @function first-three-uppercase($str) { @return str-insert(uppercase($str), 3, 1); } uses str-insert incorrectly and passes number 3 as insert string -- error.
    @function first-three-uppercase($str) { @return uppercase(str-insert($str, 3, 1)); } similar str-insert misuse -- incorrect.
  3. Final Answer:

    @function first-three-uppercase($str) { @return str-slice(uppercase($str), 1, 3); } -> Option C
  4. Quick Check:

    str-slice(uppercase($str), 1, 3) returns first 3 uppercase chars [OK]
Hint: Uppercase full string first, then slice first 3 chars [OK]
Common Mistakes:
  • Forgetting end index in str-slice causing full string slice
  • Using str-insert instead of str-slice
  • Passing numbers as insert strings causing type error
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