Complete the code to create a reactive statement that updates double when count changes.
<script> let count = 0; let double; $: double = count [1] 2; </script>
The $: syntax creates a reactive statement in Svelte. Here, double updates automatically when count changes. Multiplying by 2 doubles the value.
Complete the reactive statement to update message when name changes.
<script> let name = ""; let message; $: message = `Hello, [1]!`; </script>
message inside its own assignment causes errors.count or user.The reactive statement updates message using the current value of name. So, name must be inside the template string.
Fix the error in the reactive statement to correctly update total when price or quantity changes.
<script> let price = 5; let quantity = 3; let total; $: total = price [1] quantity; </script>
To calculate the total cost, multiply price by quantity. The reactive statement updates total whenever either changes.
Fill both blanks to create a reactive statement that updates fullName by combining firstName and lastName with a space.
<script> let firstName = "John"; let lastName = "Doe"; let fullName; $: fullName = [1] + [2]; </script>
fullName inside its own assignment causes errors.The reactive statement combines firstName and a space " ". The learner still needs to add lastName to complete the full name, but this task focuses on the first two parts.
Fill all three blanks to create a reactive statement that updates fullName by combining firstName, a space, and lastName.
<script> let firstName = "Jane"; let lastName = "Smith"; let fullName; $: fullName = [1] + [2] + [3]; </script>
fullName inside its own assignment.This reactive statement concatenates firstName, a space " ", and lastName to update fullName whenever either name changes.