Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to listen for a click event on a button.
Svelte
<button on:[1]={() => alert('Clicked!')}>Click me</button>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hover' instead of 'click' will not trigger on button press.
Using 'submit' is for forms, not buttons.
Using 'change' is for input fields, not buttons.
✗ Incorrect
The click event triggers when the user clicks the button.
2fill in blank
mediumComplete the code to update a variable when the input changes.
Svelte
<input type="text" bind:value=[1]>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' directly without declaring it.
Using 'text' which is not defined.
Using 'name' which is unrelated here.
✗ Incorrect
Binding value to inputValue updates the variable as the user types.
3fill in blank
hardFix the error in the event handler syntax.
Svelte
<button on:click=[1]>Submit</button> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses calls the function on render, not on event.
Using arrow syntax incorrectly inside the attribute.
Adding semicolons inside the attribute causes syntax errors.
✗ Incorrect
In Svelte, event handlers should be passed as references without parentheses.
4fill in blank
hardFill both blanks to create a button that increments a count on click.
Svelte
<script> let count = 0; function [1]() { count [2] 1; } </script> <button on:click={increment}>Clicked {count} times</button>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--' or '-=' decreases the count.
Using '++' alone is not valid syntax in this context.
Mismatching function name and event handler causes errors.
✗ Incorrect
The function increment adds 1 to count using the += operator.
5fill in blank
hardFill all three blanks to create an input that updates a message and shows it.
Svelte
<script> let [1] = ''; </script> <input type="text" bind:value=[2] placeholder="Type here"> <p>{ [3] }</p>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes the display not to update.
Using 'text' instead of 'message' breaks the binding.
Not binding the input value means the variable won't update.
✗ Incorrect
The variable message holds the input text and is displayed inside the paragraph.