0
0
Svelteframework~20 mins

Component file (.svelte) anatomy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Svelte Component Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this Svelte component render?
Given this Svelte component code, what will be the visible output in the browser?
Svelte
<script>
  let name = 'Anna';
</script>

<h1>Hello {name}!</h1>
AError: name is not defined
BHello {name}!
CHello Anna!
DHello !
Attempts:
2 left
💡 Hint
Look at how variables inside curly braces are replaced by their values.
📝 Syntax
intermediate
2:00remaining
Which part of this Svelte component is the script section?
Identify the script section in this Svelte component code.
Svelte
<script>
  let count = 0;
</script>

<button on:click={() => count++}>
  Clicked {count} times
</button>
A<button on:click={() => count++}>\n Clicked {count} times\n</button>
Bon:click={() => count++}
CClicked {count} times
D<script>\n let count = 0;\n</script>
Attempts:
2 left
💡 Hint
The script section is where variables and logic are declared.
lifecycle
advanced
2:00remaining
What lifecycle function runs after the component is first added to the page?
In Svelte, which lifecycle function runs only once after the component appears on the page?
AonMount
BbeforeUpdate
CafterUpdate
DonDestroy
Attempts:
2 left
💡 Hint
Think about when you want to run code after the component is visible.
🔧 Debug
advanced
2:00remaining
Why does this Svelte component fail to update the count?
This Svelte component does not update the displayed count when the button is clicked. Why?
Svelte
<script>
  let state = {count: 0};
  function increment() {
    state.count += 1;
  }
</script>

<button on:click={increment}>
  Count: {state.count}
</button>
AThe count variable is not reactive because it is not declared with $: or a store
BThe on:click event syntax is incorrect
CThe increment function is not called on button click
DThe count variable is declared inside the button element
Attempts:
2 left
💡 Hint
Top-level `let` variables trigger updates on reassignment. Object property mutations do not.
🧠 Conceptual
expert
2:00remaining
What is the role of the