Challenge - 5 Problems
Svelte Special Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does the element behave with dynamic components?
Consider the following Svelte code using . What will be rendered when
current is set to Button component?Svelte
<script> import Button from './Button.svelte'; import Label from './Label.svelte'; let current = Button; </script> <svelte:component this={current} />
Attempts:
2 left
💡 Hint
Think about how dynamically renders the component passed to it.
✗ Incorrect
❓ lifecycle
intermediate2:00remaining
What happens when listens to events?
Given this Svelte snippet, what is the effect of the element?
Svelte
<script> let width = 0; function updateWidth() { width = window.innerWidth; } </script> <svelte:window on:resize={updateWidth} /> <p>Window width: {width}</p>
Attempts:
2 left
💡 Hint
Consider what does with event listeners.
✗ Incorrect
📝 Syntax
advanced2:00remaining
What happens if wraps a {#each} block?
Examine this code snippet. What will happen?
Svelte
<script> let items = [1, 2, 3]; </script> <svelte:fragment> {#each items as item} <p>{item}</p> {/each} </svelte:fragment>
Attempts:
2 left
💡 Hint
✗ Incorrect
No error; the fragment renders all items as paragraphs. allows control flow like {#each} at top level without a wrapper DOM element.
🔧 Debug
advanced2:00remaining
How does recursive behave here?
This component uses inside its markup. What best describes the behavior?
Svelte
<script> export let count = 0; </script> {#if count < 3} <svelte:self count={count + 1} /> {/if} <p>Count: {count}</p>
Attempts:
2 left
💡 Hint
Think about how recursion works with and the count prop.
✗ Incorrect
🧠 Conceptual
expert3:00remaining
Why does handle edge cases better than manual event listeners?
Which reason best explains why using for global events is preferred over adding event listeners manually in onMount?
Attempts:
2 left
💡 Hint
Think about lifecycle and cleanup of event listeners.
✗ Incorrect