Complete the code to declare a reactive variable in Svelte.
<script> let count = 0; $: [1] = count * 2; </script>
The $: label creates a reactive statement. Here, double is the reactive variable that updates when count changes.
Complete the code to bind the input value to the variable name in Svelte.
<input type="text" [1]={name} />
value attribute which is one-way binding.bindValue.In Svelte, bind:value binds the input's value to the variable name, keeping them in sync.
Fix the error in the Svelte reactive statement to update total when items changes.
<script> let items = [1, 2, 3]; let total = 0; $: total = items[1](item => item); </script>
map which returns a new array instead of a single value.forEach which doesn't return a value.The reduce method sums all items to update total. Using map or others won't produce the sum.
Fill both blanks to create a Svelte component that conditionally shows a message when loggedIn is true.
<script>
let loggedIn = false;
</script>
{#if [1]
<p>[2] Welcome back!</p>
{/if}isLoggedIn.true directly instead of a variable.The {#if} block checks the loggedIn variable. The message uses Hello as a friendly greeting.
Fill all three blanks to create a reactive statement that updates filtered with items longer than 3 characters.
<script> let items = ['cat', 'horse', 'dog', 'elephant']; $: filtered = items[1](item => item.length [2] 3); let [3] = filtered.length; </script>
map instead of filter.length as a variable name which conflicts with property names.The filter method selects items longer than 3 characters. count stores how many items passed the filter.