0
0
Svelteframework~20 mins

Project structure in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Svelte Project Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Svelte handle component files in a project?

In a typical Svelte project, what is the role of .svelte files?

AThey are style files used only for global CSS rules.
BThey are configuration files that define project settings and dependencies.
CThey are plain JavaScript files that only export functions without UI elements.
DThey contain HTML, CSS, and JavaScript combined to define a reusable UI component.
Attempts:
2 left
💡 Hint

Think about how Svelte components combine structure, style, and behavior.

📝 Syntax
intermediate
2:00remaining
Where should you place global styles in a Svelte project?

In a Svelte project, which file is the best place to put styles that apply to the entire app?

AIn the <code>src/app.css</code> or a similar global CSS file imported in the root layout.
BInside each <code>.svelte</code> component's <code>&lt;style&gt;</code> tag with <code>scoped</code> attribute.
CDirectly inside the <code>package.json</code> file under a styles section.
DIn a JavaScript file that exports CSS strings.
Attempts:
2 left
💡 Hint

Global styles affect the whole app and are usually imported once at the top level.

🔧 Debug
advanced
2:00remaining
Why does importing a component from the wrong folder cause an error?

Given this import statement in a Svelte file:

import Button from '../components/Button.svelte';

What is the most likely cause if this import fails with a module not found error?

AThe relative path is incorrect because the file is not located in the specified folder.
BSvelte does not support importing components with relative paths.
CThe <code>.svelte</code> extension must be omitted in imports.
DThe component file must be named <code>index.svelte</code> to be imported.
Attempts:
2 left
💡 Hint

Check the folder structure and relative path carefully.

🧠 Conceptual
advanced
2:00remaining
What is the purpose of the src folder in a Svelte project?

Why do most Svelte projects have a src folder, and what should it contain?

AIt stores configuration files for the build tools and package managers.
BIt holds all source code files like components, styles, and scripts that make up the app.
CIt is used to keep static assets like images and fonts only.
DIt contains compiled JavaScript files generated after building the project.
Attempts:
2 left
💡 Hint

Think about where you write your app's code before building.

state_output
expert
3:00remaining
What will be the rendered output and state behavior of this Svelte component structure?

Consider a Svelte project with this structure:

src/
  components/
    Counter.svelte
  routes/
    +page.svelte

The Counter.svelte component has a button that increments a count state. The +page.svelte imports and uses Counter. What happens when the button is clicked?

Svelte
<!-- Counter.svelte -->
<script>
  let count = 0;
  function increment() {
    count += 1;
  }
</script>
<button on:click={increment}>Clicked {count} times</button>

<!-- +page.svelte -->
<script>
  import Counter from '../components/Counter.svelte';
</script>
<main>
  <h1>Welcome</h1>
  <Counter />
</main>
AThe button does not update the count because state cannot be changed inside components.
BClicking the button reloads the page instead of updating the count.
CThe button shows 'Clicked 0 times' initially and increments the count each click, updating the button text.
DThe component throws an error because the import path is invalid.
Attempts:
2 left
💡 Hint

Remember how Svelte components manage their own state and update the UI reactively.