Challenge - 5 Problems
Svelte Component Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this Svelte component render?
Consider this Svelte component code. What will be shown on the page when it runs?
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 the count variable updates and how Svelte reacts to changes.
✗ Incorrect
The component shows a button and a paragraph. Clicking the button runs the increment function, which updates the count variable. Svelte automatically updates the displayed count in the paragraph.
🧠 Conceptual
intermediate1:30remaining
Why are components considered building blocks in Svelte?
Which statement best explains why components are the building blocks in Svelte?
Attempts:
2 left
💡 Hint
Think about what a component contains and why that helps developers.
✗ Incorrect
Components group together HTML, CSS, and JavaScript logic. This makes it easier to reuse parts of the UI and keep code organized.
📝 Syntax
advanced1:30remaining
Identify the syntax error in this Svelte component
What is the syntax error in the following Svelte component code?
Svelte
<script> let name = 'Alice' </script> <h1>Hello {name}</h1>
Attempts:
2 left
💡 Hint
Check if semicolons are required in Svelte script blocks.
✗ Incorrect
In JavaScript, semicolons are optional. The code is valid and will render 'Hello Alice' correctly.
🔧 Debug
advanced2:00remaining
Why does this Svelte component not update the displayed message?
This component tries to update the message when the button is clicked, but the displayed text never changes. Why?
Svelte
<script> let message = 'Hello'; function update() { message = 'Goodbye'; } </script> <p>{message}</p> <button on:click="update()">Change</button>
Attempts:
2 left
💡 Hint
Look at how event handlers are attached in Svelte.
✗ Incorrect
In Svelte, event handlers use curly braces without quotes or parentheses. Using quotes and parentheses treats it as a string, so the function is not called.
❓ state_output
expert2:00remaining
What is the final output after clicking the button twice?
Given this Svelte component, what will the paragraph show after clicking the button two times?
Svelte
<script> let count = 0; function increment() { count += 1; count += 1; } </script> <button on:click={increment}>Add Two</button> <p>Count: {count}</p>
Attempts:
2 left
💡 Hint
Each click adds 2 to count. Two clicks add how much total?
✗ Incorrect
Each click runs increment, adding 2 to count. Two clicks add 4 total, so count becomes 4.