Complete the code to create a simple Svelte component that displays a greeting.
<script> let name = "World"; </script> <h1>Hello, [1]!</h1>
The variable name holds the greeting name, so we use it inside the curly braces to display the message.
Complete the code to bind the input value to the name variable in a Svelte component.
<script> let name = ""; </script> <input type="text" [1]={name} placeholder="Enter your name" /> <p>Hello, {name}!</p>
value attribute which does not update the variable.bind:name.In Svelte, bind:value connects the input's value to the variable, updating it as the user types.
Fix the error in the Svelte component to correctly import and use a child component named Button.
<script> import [1] from './Button.svelte'; </script> <[1] />
Component names in Svelte must start with a capital letter and match the import name exactly.
Fill both blanks to create a Svelte component that passes a label prop to a child Button component.
<script> import Button from './Button.svelte'; let buttonLabel = "Click me"; </script> <Button [1]=[2] />
The Button component expects a prop named label. We pass the variable buttonLabel to it.
Fill all three blanks to create a Svelte component that conditionally shows a message when showMessage is true and uses a slot for content.
<script>
let showMessage = true;
</script>
{#if [1]
<div aria-live="polite">[2]</div>
{/if}
<slot>[3]</slot>The {#if} block checks showMessage. The message is shown inside the div. The slot shows default content if no content is passed.