This code sets the page background and text color based on the $mode variable. If $mode is dark, background is black and text is white. If light, background is white and text is black. Otherwise, it uses gray background.
The first condition $theme == light is false, so it skips to @else if $theme == dark, which is true. So it applies background: black; and color: white;.
Final Answer:
body { background: black; color: white; } -> Option A
Quick Check:
$theme = dark triggers @else if dark block [OK]
Hint: Match variable value to @if conditions carefully [OK]
Common Mistakes:
Choosing first @if block without checking variable
B. Units like px cannot be compared directly in @if.
C. Comparison operators like > and < are not allowed in @if.
D. Variable $size should be declared inside the block.
Solution
Step 1: Understand unit comparison in Sass
Sass does not allow direct comparison of values with units like 10px > 5 in @if conditions.
Step 2: Check other options
Comparison operators are allowed, @else block is optional, and variables can be declared outside blocks.
Final Answer:
Units like px cannot be compared directly in @if. -> Option B
Quick Check:
Cannot compare px units directly in @if [OK]
Hint: Avoid comparing units directly; use numbers or functions [OK]
Common Mistakes:
Thinking > and < are invalid operators
Assuming @else is mandatory
Declaring variables only inside blocks
5. You want to set a button's background color based on a variable $status that can be 'success', 'warning', or 'error'. Which Sass code correctly uses @if conditional logic to apply green for success, yellow for warning, and red for error, with a default gray if none match?
In Sass, string values must be quoted and compared with ==, not = or ===.
Step 2: Verify the use of quotes around strings
Options A and B miss quotes or use wrong operators; @if $status === 'success' {
background: green;
} @else if $status === 'warning' {
background: yellow;
} @else if $status === 'error' {
background: red;
} @else {
background: gray;
} uses === which is invalid in Sass.