A. There should be no spaces around the equals sign in class:active = {isActive}.
B. The class: directive cannot be used on a <button> element.
C. The class name cannot be active.
D. The variable isActive is not declared.
Solution
Step 1: Check variable declaration
The variable isActive is declared correctly in the script block.
Step 2: Check syntax of conditional class
The syntax class:active = {isActive} has spaces around the equals sign, which is invalid in Svelte. It should be class:active={isActive} without spaces.
Final Answer:
There should be no spaces around the equals sign in class:active = {isActive}. -> Option A
Quick Check:
No spaces around = in class:name={condition} [OK]
Hint: No spaces around = in class:name={condition} [OK]
Common Mistakes:
Adding spaces around = sign
Thinking class:name can't be on button
Missing variable declaration
5. You want to add two conditional classes visible and highlight to a <div> in Svelte. visible should be added when isVisible is true, and highlight only when isHighlighted is also true and isVisible is true.
Which of the following is the correct way to write this?