Complete the code to update the count variable reactively when the button is clicked.
let count = 0; function increment() { count [1] 1; }
Using count += 1 increases the count by one and triggers reactive updates in Svelte.
Complete the code to trigger a reactive update by reassigning the array after pushing a new item.
let items = [];
function addItem(item) {
items.push(item);
items = [1];
}items.push() returns the new length, not the array.items.pop() removes an item instead of triggering update.Reassigning items = items triggers Svelte's reactivity even after mutating the array.
Fix the error in the reactive assignment to update the object property correctly.
let user = { name: 'Alice', age: 25 };
function updateAge(newAge) {
user.age [1] newAge;
user = user;
}Assigning user.age = newAge updates the property, then reassigning user = user triggers the reactive update.
Fill both blanks to update a nested object property reactively.
let settings = { theme: { color: 'blue' } };
function changeColor(newColor) {
settings.theme.[1] = [2];
settings = settings;
}Assigning settings.theme.color = newColor changes the nested property, then reassigning settings = settings triggers the update.
Fill all three blanks to update a reactive array element and trigger the update.
let scores = [10, 20, 30]; function updateScore(index, value) { scores[[1]] = [2]; scores = [3]; }
We assign scores[index] = value to update the element, then reassign scores = scores to trigger reactivity.