Complete the code to display the page title using a variable.
<script> let title = 'Welcome to Svelte'; </script> <h1>[1]</h1>
In Svelte, to show a variable's value in the HTML, you wrap it in curly braces like {title}.
Complete the code to bind the input value to the variable 'name'.
<script> let name = ''; </script> <input type="text" [1] /> <p>Hello, {name}!</p>
In Svelte, bind:value={name} links the input's value to the variable name, updating it as the user types.
Fix the error in the code to correctly display a list of items.
<script> let items = ['apple', 'banana', 'cherry']; </script> <ul> {#each items as [1] <li>{item}</li> {/each} </ul>
The {#each} block needs a variable name for each item, commonly item, to use inside the loop.
Fill both blanks to create a reactive statement that updates 'double' when 'count' changes.
<script> let count = 0; $: [1] = [2] * 2; </script> <p>Double: {double}</p>
The reactive statement uses $: double = count * 2; to update double whenever count changes.
Fill all three blanks to create a page that fetches data and displays it.
<script> import { onMount } from 'svelte'; let data = []; onMount(async () => { const response = await fetch([1]); data = await response.[2](); }); </script> <ul> {#each data as [3] <li>{item.name}</li> {/each} </ul>
response.text() instead of json().The fetch URL is a string, the response is parsed with json(), and each item is named item in the loop.