0
0
SASSmarkup~20 mins

Why variables reduce repetition in SASS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Variable Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use variables in Sass?
Which of the following best explains why using variables in Sass helps reduce repetition?
AVariables make the website load faster by compressing the CSS code.
BVariables automatically change colors on the website without any code changes.
CVariables let you store values once and reuse them, so you don’t have to write the same value multiple times.
DVariables replace all CSS selectors with shorter names to save space.
Attempts:
2 left
πŸ’‘ Hint
Think about how you might use the same color or size many times in your styles.
πŸ“ Syntax
intermediate
2: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: ???;
}
Abackground-color: $primary-color;
Bbackground-color: primary-color;
Cbackground-color: #primary-color;
Dbackground-color: var(primary-color);
Attempts:
2 left
πŸ’‘ Hint
Remember Sass variables start with a $ sign and are used directly by name.
❓ rendering
advanced
2: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;
}
AThe button with class 'button' will be red (#e74c3c), and the button with classes 'button secondary' will be green (#2ecc71).
BBoth buttons will be green (#2ecc71).
CBoth buttons will be red (#e74c3c).
DThe button with class 'button' will be green, and the 'button secondary' will be red.
Attempts:
2 left
πŸ’‘ Hint
Look at which variable is used in each selector.
❓ selector
advanced
2: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?
AVariables automatically add vendor prefixes to selectors for better browser support.
BUsing a variable means you only change the font size in one place, and all selectors using that variable update automatically.
CVariables let you write selectors faster by shortening their names.
DVariables prevent selectors from being overridden by other styles.
Attempts:
2 left
πŸ’‘ Hint
Think about what happens if you want to change the font size later.
❓ accessibility
expert
3: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?
AVariables prevent colors from being changed accidentally by locking them.
BVariables automatically check color contrast and fix it for you.
CVariables let you hide colors from screen readers to improve accessibility.
DBy changing the color variables, all elements using them update, making it easier to keep contrast consistent and accessible.
Attempts:
2 left
πŸ’‘ Hint
Think about how changing one value affects many parts of your site.