Challenge - 5 Problems
Fade Transition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when the fade transition is applied?
Consider a Svelte component that uses
transition:fade on a paragraph. What will the user see when the paragraph is removed from the DOM?Svelte
<script> import { fade } from 'svelte/transition'; let visible = true; </script> <button on:click={() => visible = !visible}>Toggle</button> {#if visible} <p transition:fade>This text will fade out when hidden.</p> {/if}
Attempts:
2 left
💡 Hint
Think about what the
fade transition does visually.✗ Incorrect
The fade transition smoothly changes the element's opacity from fully visible to invisible before removing it from the DOM.
📝 Syntax
intermediate2:00remaining
Which option correctly applies the fade transition with a duration of 500ms?
You want to apply the fade transition to a div with a custom duration of 500 milliseconds. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Check the syntax for passing parameters to transitions in Svelte.
✗ Incorrect
The correct syntax uses curly braces inside the directive with a JavaScript object, spaced properly: transition:fade={{ duration: 500 }}.
🔧 Debug
advanced2:00remaining
Why does the fade transition not run on initial render?
Given this Svelte code, the fade transition does not animate when the paragraph first appears. Why?
Svelte
<script> import { fade } from 'svelte/transition'; let show = true; </script> {#if show} <p transition:fade>This text appears immediately without fade-in.</p> {/if}
Attempts:
2 left
💡 Hint
Think about when Svelte applies transitions by default.
✗ Incorrect
Svelte applies transitions only when elements enter or leave the DOM after initial render. Elements present initially do not animate by default.
❓ state_output
advanced2:00remaining
What is the value of
visible after the fade transition completes?In this Svelte component, what is the value of
visible after the fade transition finishes when toggling off?Svelte
<script> import { fade } from 'svelte/transition'; let visible = true; function toggle() { visible = !visible; } </script> <button on:click={toggle}>Toggle</button> {#if visible} <p transition:fade>This text fades in and out.</p> {/if}
Attempts:
2 left
💡 Hint
Consider when the state variable changes relative to the transition animation.
✗ Incorrect
The visible variable changes immediately when the button is clicked. The fade transition animates the element leaving the DOM, but the state is already updated.
🧠 Conceptual
expert3:00remaining
Which statement best describes the difference between
transition:fade and in:fade in Svelte?Choose the option that correctly explains how
transition:fade differs from in:fade.Attempts:
2 left
💡 Hint
Think about when each directive triggers animations.
✗ Incorrect
transition:fade applies fade animation on both entering and leaving the DOM. in:fade applies fade only when the element appears.