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 3
By completing this activity, you will:
export let to define component propsIMPORTANT: This template provides a 70% pre-built foundation!
Already implemented for you:
player and score props, styled cardsnum1 and num2 props and calculation{...studentData} to pass all props at onceactivity-03-svelte-props/
โโโ README.md # This file
โโโ 01-player-score/
โ โโโ App.svelte # 100% complete
โ โโโ Score.svelte # 100% complete
โโโ 02-multiply-calculator/
โ โโโ App.svelte # 100% complete
โ โโโ Multiply.svelte # 100% complete
โโโ 03-student-card/
โโโ App.svelte # 40% complete - needs data object
โโโ Card.svelte # 100% complete
Create a JavaScript object with all student information properties.
File: 03-student-card/App.svelte
Success Criteria:
studentData object variable using letschool property (e.g., "Telebort Academy")name property (e.g., "John Doe")studentID property (e.g., "TB2024001")year property (e.g., "2024")Code Location: App.svelte - Inside <script> tag after the import
Hint: Look at Activity 1's code for examples of passing props. Now instead of passing them one by one, you'll create an object with all the data.
Example Pattern:
let studentData = {
school: "Your School Name",
name: "Your Name",
studentID: "Your ID",
year: "Your Year"
};
Pass all props to the Card component using the spread operator.
File: 03-student-card/App.svelte
Success Criteria:
{...studentData}Code Location: App.svelte - The <Card /> component line
Hint: Instead of writing <Card school={studentData.school} name={studentData.name} ...>, you can use <Card {...studentData} /> to pass all properties at once!
Before (Manual Props):
<Card school={data.school} name={data.name} studentID={data.studentID} year={data.year} />
After (Spread Syntax):
<Card {...studentData} />
By examining the working code and completing the TODOs, you'll understand:
player="1" to send data{...obj} is cleaner than listing 10+ props manuallyScore.svelte:
<script>
export let player;
export let score;
</script>
<div>
<p>Player {player}</p>
<p>Score: {score}</p>
</div>
<style>
div{
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.5);
padding: 0.5rem;
margin: 12px 40px;
border-radius: 5px;
text-align: center;
font-weight: bold;
}
p{
margin: 0;
}
</style>
App.svelte:
<script>
import Score from "./Score.svelte";
</script>
<Score player="1" score="100" />
<Score player="2" score="250" />
<Score player="3" score="180" />
Multiply.svelte:
<script>
export let num1;
export let num2;
let answer = num1 * num2;
</script>
<p>{num1} x {num2} = {answer}</p>
App.svelte:
<script>
import Multiply from "./Multiply.svelte";
</script>
<Multiply num1="3" num2="8" />
Card.svelte (100% Complete):
<script>
export let school;
export let name;
export let studentID;
export let year;
</script>
<div class="card">
<h1>{school}</h1>
<p class="stu">Student</p>
<h1>:)</h1>
<p>{name}</p>
<p>{studentID}</p>
<p>INTAKE: {year}</p>
</div>
<style>
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.5);
padding: 2px 16px;
margin: 12px 4px;
border-radius: 5px;
text-align: center;
font-weight: bold;
}
</style>
App.svelte (40% Complete - YOUR TURN!):
<script>
import Card from "./Card.svelte";
// TODO 1: Create studentData object here
// let studentData = {
// school: "Telebort Academy",
// name: "John Doe",
// studentID: "TB2024001",
// year: "2024"
// };
</script>
<!-- TODO 2: Replace this line with spread syntax -->
<Card school="" name="" studentID="" year="" />
<!-- Should become: <Card {...studentData} /> -->
Your activity is complete when:
{...studentData} spread syntaxTest these scenarios in Svelte REPL:
Props Passing:
Object Spread:
Component Reusability:
<Card {...studentData2} />Prop Types:
Issue: "Cannot read property of undefined" Solution: Make sure object property names match component prop names exactly (case-sensitive!)
Issue: Props not updating
Solution: Ensure you used export let propName in the child component
Issue: Spread syntax not working Solution:
{...objectName} not ...objectNameIssue: Student card is blank Solution: Check that all 4 properties exist in studentData object
Issue: Styling not appearing
Solution: Make sure you copied the entire component including the <style> section
Ready for more? Try these bonus features:
export let name = "Unknown"../../Activities/Activity 03- Svelte Props.mdxWhen you've completed all three activities:
Remember: Props are how components communicate. Master props, and you can build complex applications from simple, reusable pieces!
๐ก Pro Tip: The spread operator {...object} is extremely powerful. You'll use it constantly in modern web development - not just in Svelte, but in React, Vue, and plain JavaScript too!