Recall & Review
beginner
What does
class:name={condition} do in Svelte?It adds the CSS class <code>name</code> to the element only if <code>condition</code> is true. If false, the class is not added.Click to reveal answer
beginner
How do you apply multiple conditional classes in Svelte?
You write multiple <code>class:name={condition}</code> attributes on the same element, each controlling one class based on its condition.Click to reveal answer
intermediate
Can you use expressions inside the condition of
class:name={condition}?Yes, you can use any JavaScript expression that evaluates to true or false inside the curly braces to control the class application.Click to reveal answer
intermediate
What happens if the condition in
class:name={condition} changes during runtime?Svelte automatically updates the element's classes to add or remove the class
name based on the new condition value.Click to reveal answer
beginner
Why is using
class:name={condition} better than manually toggling classes with JavaScript in Svelte?Because it keeps your code clean, declarative, and reactive. Svelte handles class changes automatically without extra code.Click to reveal answer
What does
class:active={isActive} do in Svelte?✗ Incorrect
The syntax adds the class 'active' only when the condition is true.
How can you add two conditional classes 'red' and 'bold' based on variables in Svelte?
✗ Incorrect
You add multiple class directives separately for each class and condition.
If
class:highlight={score > 50} is used, when is the 'highlight' class applied?✗ Incorrect
The class is added only if the condition (score > 50) is true.
What happens if the condition in
class:name={condition} changes from true to false?✗ Incorrect
Svelte removes the class automatically when the condition becomes false.
Which is a benefit of using
class:name={condition} in Svelte?✗ Incorrect
It makes class toggling easy and reactive without manual DOM manipulation.
Explain how to use conditional classes in Svelte and why it helps with reactive UI.
Think about how Svelte updates classes when variables change.
You got /4 concepts.
Describe how you would add multiple conditional classes to an element in Svelte.
Remember each class gets its own class:name attribute.
You got /3 concepts.