Challenge - 5 Problems
Variable Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
π§ Conceptual
intermediate2:00remaining
Why use variables in Sass?
Which of the following best explains why using variables in Sass helps reduce repetition?
Attempts:
2 left
π‘ Hint
Think about how you might use the same color or size many times in your styles.
β Incorrect
Variables store a value once, like a color or size, so you can reuse it everywhere. This means you write the value only once, reducing repetition and making updates easier.
π Syntax
intermediate2:00remaining
Identify the correct Sass variable usage
Which option shows the correct way to define and use a variable for a primary color in Sass?
SASS
$primary-color: #3498db; .button { background-color: ???; }
Attempts:
2 left
π‘ Hint
Remember Sass variables start with a $ sign and are used directly by name.
β Incorrect
In Sass, variables start with a $ and are used by writing the $ followed by the variable name. So $primary-color is correct.
β rendering
advanced2:00remaining
What color will the button have?
Given the Sass code below, what color will the button background be when compiled to CSS and viewed in a browser?
SASS
$main-color: #e74c3c; $secondary-color: #2ecc71; .button { background-color: $main-color; } .button.secondary { background-color: $secondary-color; }
Attempts:
2 left
π‘ Hint
Look at which variable is used in each selector.
β Incorrect
The .button class uses $main-color (#e74c3c), so it will be red. The .button.secondary class uses $secondary-color (#2ecc71), so it will be green.
β selector
advanced2:00remaining
How do variables help with selector consistency?
If you want to use the same font size in many selectors, how does using a Sass variable help compared to writing the font size directly each time?
Attempts:
2 left
π‘ Hint
Think about what happens if you want to change the font size later.
β Incorrect
When you use a variable for font size, changing the variable value updates all selectors that use it, keeping styles consistent and saving time.
β accessibility
expert3:00remaining
Using variables to maintain accessible color contrast
You have variables for background and text colors in Sass. How can using variables help maintain good color contrast for accessibility when you update your design?
Attempts:
2 left
π‘ Hint
Think about how changing one value affects many parts of your site.
β Incorrect
Using variables for colors means you can update colors in one place and ensure all text and backgrounds maintain good contrast, which is important for accessibility.