Challenge - 5 Problems
Svelte Template Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Svelte component render?
Consider this Svelte component code. What will be displayed on the page when it runs?
Svelte
<script> let name = 'Alice'; </script> <h1>Hello {name}!</h1>
Attempts:
2 left
💡 Hint
Look at how the curly braces { } are used in Svelte templates.
✗ Incorrect
Svelte replaces {name} with the value of the variable 'name', so it renders 'Hello Alice!'.
❓ state_output
intermediate2:00remaining
How does updating a variable affect the rendered output?
Given this Svelte component, what will be the displayed text after clicking the button once?
Svelte
<script> let count = 0; function increment() { count += 1; } </script> <button on:click={increment}>Click me</button> <p>Count: {count}</p>
Attempts:
2 left
💡 Hint
Think about how Svelte updates the DOM when variables change.
✗ Incorrect
Clicking the button calls increment(), which increases count by 1, so the displayed count updates to 1.
📝 Syntax
advanced2:00remaining
Which option correctly uses Svelte template syntax to show a message only if loggedIn is true?
Select the code snippet that will display 'Welcome back!' only when the variable loggedIn is true.
Attempts:
2 left
💡 Hint
Svelte uses special block syntax with #if and {/if} inside curly braces.
✗ Incorrect
Option D uses the correct Svelte syntax for conditional rendering. Others are invalid or incorrect.
🔧 Debug
advanced2:00remaining
Why does this Svelte template show the literal text '{user}' instead of the username?
This component code is supposed to show the username, but it shows '{user}' literally. What is the cause?
Svelte
<script> let user = 'Bob'; </script> <p>{'{user}'}</p>
Attempts:
2 left
💡 Hint
Check how strings and variables are used inside curly braces in Svelte.
✗ Incorrect
The template uses '{'{user}'}' which is a string containing curly braces, so Svelte renders it literally.
🧠 Conceptual
expert3:00remaining
Why does Svelte update the DOM automatically when a variable changes?
Choose the best explanation for why Svelte's template syntax renders dynamic content that updates automatically when variables change.
Attempts:
2 left
💡 Hint
Think about how Svelte differs from frameworks that use virtual DOM.
✗ Incorrect
Svelte compiles templates into optimized JavaScript that updates only what changed, without using a virtual DOM.