Student starter code (30% baseline)
index.html- Main HTML pagescript.js- JavaScript logicstyles.css- Styling and layoutpackage.json- Dependenciessetup.sh- Setup scriptREADME.md- Instructions (below)๐ก Download the ZIP, extract it, and follow the instructions below to get started!
W3 Server-Side Development & Authentication - Lesson 6
By completing this activity, you will:
bind: directiveTotal Activity Time: 60-75 minutes
IMPORTANT: This template includes a WORKING foundation with 70% pre-built!
App.svelte in this folderOrder.svelte and copy that code too70% of the code is implemented for you:
popUp() function fully workingbind:value to connect input to variable (5%)Files: App.svelte - Lines 8 and 15
Time: 5 minutes
Connect the input field to the name variable using two-way data binding.
Success Criteria:
bind:value={name} to the input elementHint: The bind: directive creates a two-way connection. When the input changes, the variable updates. When the variable changes, the input updates.
Example Pattern:
<input type="text" bind:value={variableName}>
File: App.svelte - Lines 26-36
Time: 10 minutes
Add reactive validation to ensure both numbers stay within 0-20 range.
Success Criteria:
$: for reactive statementsnumber1 < 0 || number1 > 20number2 with same validationHint: Create two separate reactive statements, one for each number. Each should follow the same pattern.
Example Pattern:
$: if (variable < min || variable > max) {
alert("message");
variable = resetValue;
}
Files: App.svelte and Order.svelte
Time: 15 minutes
Implement two-way binding between parent (App) and child (Order) components.
Success Criteria:
Order.svelte: Export cName and flavor propsOrder.svelte: Bind text input to cNameOrder.svelte: Bind radio group to flavorApp.svelte: Import Order componentApp.svelte: Use bind:cName={cName} and bind:flavor={flavor}Hint: For radio buttons, use bind:group instead of bind:value. All radio buttons in the same group should bind to the same variable but have different value attributes.
Example Pattern:
<!-- Child component -->
<script>
export let propName;
</script>
<input type="radio" bind:group={propName} value="option1">
<!-- Parent component -->
<script>
import Child from './Child.svelte';
let propName = "";
</script>
<Child bind:propName={propName} />
Files: App.svelte and Order.svelte
Time: 15-20 minutes
Take the ice cream shop to the next level with styling and features.
Success Criteria:
Enhancement Ideas:
{vanilla: 3, chocolate: 4, ...}By examining the working code and completing the TODOs, you'll understand:
bind:value creates live connection between UI and data$: with binding for instant validationexport let to create bindable propsTest these scenarios:
Activity 1 (After TODO #1):
Activity 2 (After TODO #2):
Activity 3 (After TODO #3):
Activity 4 (After TODO #4):
Your project is complete when:
Activity 1:
name variableActivity 2:
{number1} รท {number2} = {result}Activity 3:
bind:groupActivity 4 (Optional):
| Binding Type | Syntax | Use Case |
|---|---|---|
| Text/Number Input | bind:value={variable} |
Two-way data binding |
| Radio Buttons | bind:group={variable} |
Single selection from group |
| Checkbox | bind:checked={variable} |
Boolean on/off state |
| Component Props | bind:propName={variable} |
Parent-child communication |
| Reactive Validation | $: if (condition) {...} |
Auto-run validation |
รท or HTML entity ÷< or <> or >Issue: Binding not working, changes don't appear
Solution: Check you're using curly braces {variable} not "variable" in strings
Issue: Radio buttons not grouping correctly
Solution: All buttons in group must use same bind:group variable but different value attributes
Issue: Validation not triggering
Solution: Make sure you're using $: for reactive statements, not regular if statements
Issue: Component props not updating
Solution: Use bind: when passing props from parent, and export let in child component
Issue: Number input accepting any value Solution: Add reactive statement with proper range check and reset logic
Ready for more? Try these bonus features:
Beginner Extensions:
Advanced Extensions:
Creative Extensions:
../../Activities/Activity 06- Svelte Data Binding.mdxRemember: Data binding is what makes modern web apps feel responsive and intuitive. With Svelte's bind: directive, you get two-way synchronization automatically - no boilerplate code needed!
๐ก Pro Tip: When debugging bindings, add console.log(variable) inside reactive statements ($: console.log(name)) to see when values change. This helps you understand the data flow!