0
0
Svelteframework~20 mins

Script, markup, and style sections in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Svelte Script-Markup-Style Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered output of this Svelte component?

Consider this Svelte component code:

<script>
  let count = 2;
</script>

<h1>Count is {count * 3}</h1>

<style>
  h1 { color: blue; }
</style>

What will you see on the page?

Svelte
<script>
  let count = 2;
</script>

<h1>Count is {count * 3}</h1>

<style>
  h1 { color: blue; }
</style>
AA black heading that says: Count is 2
BA blue heading that says: Count is 2
CA black heading that says: Count is 6
DA blue heading that says: Count is 6
Attempts:
2 left
💡 Hint

Remember the expression inside curly braces is evaluated.

📝 Syntax
intermediate
1:30remaining
Which script section syntax is correct in Svelte?

Which of these script sections is valid in a Svelte component?

A<script export let name;> </script>
B<script> export let name; </script>
C<script context="module"> export let name; </script>
D<script context=module> export let name; </script>
Attempts:
2 left
💡 Hint

Look for correct attribute syntax and placement.

🔧 Debug
advanced
2:00remaining
Why does this style not apply in Svelte?

Given this Svelte component:

<script>
  let color = 'red';
</script>

<h2 class="title">Hello</h2>

<style>
  .title { color: {color}; }
</style>

Why does the heading not appear red?

Svelte
<script>
  let color = 'red';
</script>

<h2 class="title">Hello</h2>

<style>
  .title { color: {color}; }
</style>
AThe color variable is not declared in the script
BThe class name is wrong, so style does not apply
CSvelte style tags do not support JavaScript variables inside CSS blocks
DThe style tag must be inside the script tag
Attempts:
2 left
💡 Hint

Think about how CSS and JavaScript interact in Svelte.

🧠 Conceptual
advanced
1:30remaining
What is the role of the