Challenge - 5 Problems
Svelte Text Interpolation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this Svelte component display?
Consider this Svelte component code. What text will appear on the page?
Svelte
<script> let name = 'Alice'; let age = 30; </script> <p>Hello, {name}! You are {age} years old.</p>
Attempts:
2 left
💡 Hint
Remember that Svelte replaces expressions inside curly braces with their values.
✗ Incorrect
Svelte replaces {name} and {age} with their current values, so the output is 'Hello, Alice! You are 30 years old.'
📝 Syntax
intermediate1:30remaining
Which option correctly uses text interpolation in Svelte?
Choose the option that correctly shows the user's score stored in a variable called score.
Svelte
let score = 85;
Attempts:
2 left
💡 Hint
Svelte uses curly braces {} for interpolation, not other symbols.
✗ Incorrect
In Svelte, you use {variable} inside markup to show the variable's value. Other syntaxes are invalid.
❓ state_output
advanced2:00remaining
What is the output after clicking the button twice?
This Svelte component increments a counter when the button is clicked. What text is shown after two clicks?
Svelte
<script> let count = 0; function increment() { count += 1; } </script> <button on:click={increment}>Click me</button> <p>Clicked {count} times.</p>
Attempts:
2 left
💡 Hint
Each click increases count by 1, and the text shows the current count.
✗ Incorrect
After two clicks, count is 2, so the text shows 'Clicked 2 times.'
🔧 Debug
advanced2:00remaining
Why does this Svelte component show {message} literally instead of the message value?
Look at this code snippet. Why does the page show '{message}' instead of 'Hello World'?
Svelte
<script> let message = 'Hello World'; </script> <p>{'{message}'}</p>
Attempts:
2 left
💡 Hint
Check how the curly braces are used inside the paragraph tag.
✗ Incorrect
The curly braces are inside quotes, so Svelte outputs them as text, not as an expression to evaluate.
🧠 Conceptual
expert2:30remaining
What happens if you use a JavaScript expression inside Svelte interpolation?
Consider this code snippet. What will be displayed?
Svelte
<script> let a = 5; let b = 3; </script> <p>{a > b ? 'a is greater' : 'b is greater or equal'}</p>
Attempts:
2 left
💡 Hint
Svelte supports JavaScript expressions inside curly braces.
✗ Incorrect
The expression evaluates to true since 5 > 3, so 'a is greater' is displayed.