📖 Scenario: You are building a simple SvelteKit app that shows a list of fruits and highlights the ones you like.
🎯 Goal: Create a SvelteKit component that displays a list of fruits from a data array, uses a configuration variable to mark favorite fruits, and renders the list with favorite fruits styled differently.
📋 What You'll Learn
Create a fruits array with exact fruit names
Add a favoriteFruits array to hold favorite fruit names
Use a {#each} block to loop over fruits
Highlight favorite fruits with a CSS class
Use semantic HTML and accessible markup
💡 Why This Matters
🌍 Real World
SvelteKit is used to build fast, modern web apps with reactive UI and server-side rendering. Managing data and UI state like this is common in real projects.
💼 Career
Understanding SvelteKit basics helps you work on frontend roles that use this popular framework for building interactive websites and apps.
Progress0 / 4 steps
1
DATA SETUP: Create the fruits array
Create a fruits array with these exact strings: "Apple", "Banana", "Cherry", "Date", and "Elderberry".
Svelte
Hint
Use export let fruits = [...] to define the array in SvelteKit.
2
CONFIGURATION: Define favorite fruits
Add a new exported array called favoriteFruits with these exact strings: "Apple" and "Date".
Svelte
Hint
Use export let favoriteFruits = [...] to define the favorites.
3
CORE LOGIC: Loop over fruits and highlight favorites
Use a {#each fruits as fruit} block to display each fruit inside a <li>. Add a class favorite to the <li> if fruit is included in favoriteFruits using class:favorite={favoriteFruits.includes(fruit)}.
Svelte
Hint
Use Svelte's {#each} block and conditional class binding.
4
COMPLETION: Add CSS to style favorite fruits
Add a <style> block with CSS that sets color: red; for the .favorite class to highlight favorite fruits in red.
Svelte
Hint
Use CSS inside the <style> block to style the favorite fruits.
Practice
(1/5)
1. What is the main purpose of SvelteKit in web development?
easy
A. To manage databases and server hardware
B. To create mobile apps using native code
C. To design static images and graphics
D. To build fast, modern web apps with minimal setup
Solution
Step 1: Understand SvelteKit's role
SvelteKit is a framework designed to help developers build web applications quickly and efficiently.
Step 2: Identify the main feature
It focuses on fast performance and less setup compared to traditional methods.
Final Answer:
To build fast, modern web apps with minimal setup -> Option D
Quick Check:
SvelteKit = fast web apps with less setup [OK]
Hint: Remember SvelteKit is for fast web apps, not mobile or graphics [OK]
Common Mistakes:
Confusing SvelteKit with mobile app frameworks
Thinking it manages databases directly
Assuming it is for graphic design
2. Which file naming pattern does SvelteKit use to create routes automatically?
easy
A. Files inside the src/routes folder
B. Files inside the src/components folder
C. Files inside the public/assets folder
D. Files inside the src/styles folder
Solution
Step 1: Recall SvelteKit routing system
SvelteKit uses file-based routing, where files in a specific folder define pages.
Step 2: Identify the correct folder
The src/routes folder contains files that become routes automatically.
Final Answer:
Files inside the src/routes folder -> Option A
Quick Check:
Routes = files in src/routes [OK]
Hint: Routes come from src/routes folder files [OK]
Common Mistakes:
Choosing components folder for routes
Confusing public assets with routes
Thinking styles folder controls routing
3. Given this SvelteKit page code, what will be rendered?