Bird
Raised Fist0
Svelteframework~20 mins

Progressive enhancement in Svelte - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Progressive Enhancement Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What will this Svelte component render initially?

Consider this Svelte component that uses progressive enhancement to show a message only if JavaScript is enabled.

<noscript>Please enable JavaScript to see the message.</noscript>
<script>
  let showMessage = false;
  onMount(() => {
    showMessage = true;
  });
</script>

{#if showMessage}
  <p>JavaScript is enabled!</p>
{/if}

What will the user see if JavaScript is disabled?

Svelte
<noscript>Please enable JavaScript to see the message.</noscript>
<script>
  import { onMount } from 'svelte';
  let showMessage = false;
  onMount(() => {
    showMessage = true;
  });
</script>

{#if showMessage}
  <p>JavaScript is enabled!</p>
{/if}
AThe message 'JavaScript is enabled!' is shown.
BNo message is shown at all.
CThe message 'Please enable JavaScript to see the message.' is shown.
DBoth messages are shown simultaneously.
Attempts:
2 left
💡 Hint

Think about what the <noscript> tag does when JavaScript is disabled.

❓ state_output
intermediate
2:00remaining
What is the final value of count after this Svelte component runs?

This Svelte component increments a counter only if JavaScript is enabled. What is the value of count after the component mounts?

<noscript></noscript>
<script>
  import { onMount } from 'svelte';
  let count = 0;
  onMount(() => {
    count += 1;
  });
</script>

<p>Count: {count}</p>
Svelte
<noscript></noscript>
<script>
  import { onMount } from 'svelte';
  let count = 0;
  onMount(() => {
    count += 1;
  });
</script>

<p>Count: {count}</p>
A1
B0
Cundefined
DNaN
Attempts:
2 left
💡 Hint

Remember when onMount runs in Svelte.

📝 Syntax
advanced
2:00remaining
Which option correctly implements progressive enhancement for a button that works without JavaScript?

You want a button that submits a form normally if JavaScript is disabled, but uses Svelte's event handler when JavaScript is enabled. Which code snippet achieves this?

A<button type="submit" on:click={handleClick}>Submit</button>
B<button type="submit" on:click|preventDefault={handleClick}>Submit</button>
C<button type="button" on:click={handleClick}>Submit</button>
D<button on:click={handleClick}>Submit</button>
Attempts:
2 left
💡 Hint

Think about the default behavior of a submit button and how to preserve it when JavaScript is disabled.

🔧 Debug
advanced
2:00remaining
Why does this Svelte progressive enhancement code fail to show the fallback message?

Given this code, the fallback message inside <noscript> does not appear when JavaScript is disabled. Why?

<script>
  let jsEnabled = false;
  onMount(() => {
    jsEnabled = true;
  });
</script>

{#if !jsEnabled}
  <noscript>Please enable JavaScript</noscript>
{/if}
Svelte
<script>
  import { onMount } from 'svelte';
  let jsEnabled = false;
  onMount(() => {
    jsEnabled = true;
  });
</script>

{#if !jsEnabled}
  <noscript>Please enable JavaScript</noscript>
{/if}
AThe <noscript> tag cannot be used inside Svelte blocks.
BThe <noscript> tag is inside a Svelte conditional, so it never renders when JS is disabled.
CThe variable jsEnabled is never updated because onMount does not run without JS.
DThe condition !jsEnabled is always false, so the block never shows.
Attempts:
2 left
💡 Hint

Consider how <noscript> works and when Svelte renders blocks.

🧠 Conceptual
expert
2:00remaining
Which statement best describes progressive enhancement in Svelte applications?

Choose the statement that most accurately explains how progressive enhancement works in Svelte.

ASvelte uses progressive enhancement by disabling JavaScript features if the user prefers reduced motion.
BSvelte apps always require JavaScript; progressive enhancement is not applicable.
CProgressive enhancement in Svelte means loading all components on the server and never using client-side JavaScript.
DProgressive enhancement means providing basic HTML content that works without JavaScript, then enhancing it with Svelte's reactive features when JS is enabled.
Attempts:
2 left
💡 Hint

Think about how Svelte can deliver content that works with or without JavaScript.

Practice

(1/5)
1. What is the main goal of progressive enhancement in Svelte applications?
easy
A. To load all data at once for faster performance
B. To use only JavaScript for all app functionality
C. To avoid using semantic HTML elements
D. To make sure the app works with basic features before adding advanced ones

Solution

  1. Step 1: Understand the concept of progressive enhancement

    Progressive enhancement means starting with a simple, working version of the app that everyone can use.
  2. Step 2: Identify the goal in Svelte apps

    In Svelte, this means building basic content first, then adding interactive features on top.
  3. Final Answer:

    To make sure the app works with basic features before adding advanced ones -> Option D
  4. Quick Check:

    Progressive enhancement = basic first, then advanced [OK]
Hint: Think: start simple, then add features [OK]
Common Mistakes:
  • Assuming JavaScript must be used for everything
  • Ignoring basic content for advanced features
  • Skipping semantic HTML importance
2. Which of the following is the correct way to provide fallback content for users without JavaScript in a Svelte app?
easy
A.

Enable JavaScript to see this app.

B.
C.
No JS support
D. Enable JS

Solution

  1. Step 1: Identify the HTML element for no-JavaScript fallback

    The tag is designed to show content only when JavaScript is disabled.
  2. Step 2: Check the options for correct usage

    Enable JavaScript to see this app.

    uses correctly with fallback text. Others misuse tags or won't show fallback properly.
  3. Final Answer:

    <noscript><p>Enable JavaScript to see this app.</p></noscript> -> Option A
  4. Quick Check:

    Fallback for no JS = <noscript> [OK]
Hint: Use <noscript> for no-JS fallback content [OK]
Common Mistakes:
  • Using <script> to detect JS absence
  • Hiding fallback with CSS only
  • Using <template> which doesn't render
3. Given this Svelte snippet for progressive enhancement:
<button aria-label="Toggle menu" on:click={toggleMenu}>Menu</button>
<nav class:open={menuOpen}>...</nav>

What happens if JavaScript is disabled in the browser?
medium
A. The menu is always visible because class binding works without JS
B. The button does nothing and the menu stays hidden
C. The button triggers toggleMenu even without JS
D. The menu is removed from the DOM

Solution

  1. Step 1: Understand Svelte event handling and class binding

    The on:click event and class:open binding require JavaScript to work.
  2. Step 2: Consider no JavaScript scenario

    Without JS, the button click does nothing and the class:open is not applied, so the menu stays hidden if initially hidden.
  3. Final Answer:

    The button does nothing and the menu stays hidden -> Option B
  4. Quick Check:

    JS off means no event or class binding [OK]
Hint: JS needed for event and class bindings [OK]
Common Mistakes:
  • Thinking class binding works without JS
  • Assuming button triggers function without JS
  • Believing menu auto-shows without JS
4. You wrote this Svelte code for progressive enhancement:
<button on:click={toggle} aria-expanded={expanded}>Toggle</button>
<div hidden={!expanded}>Content</div>

But the content never shows when clicking the button. What is the likely problem?
medium
A. The hidden attribute does not toggle correctly with boolean binding
B. The aria-expanded attribute must be a string, not boolean
C. The toggle function is missing or not updating expanded
D. The on:click event is not supported in Svelte

Solution

  1. Step 1: Check event and state connection

    The button's on:click calls toggle, which should update expanded state.
  2. Step 2: Identify missing or broken toggle function

    If toggle is missing or doesn't update expanded, the hidden attribute never changes, so content stays hidden.
  3. Final Answer:

    The toggle function is missing or not updating expanded -> Option C
  4. Quick Check:

    Missing toggle function = no state change [OK]
Hint: Ensure toggle updates state variable [OK]
Common Mistakes:
  • Thinking hidden attribute toggles automatically
  • Confusing aria-expanded type requirements
  • Believing on:click is unsupported in Svelte
5. You want to build a Svelte app that shows a list of items with a button to filter them. For progressive enhancement, which approach is best?
hard
A. Render the full list in HTML first, then use Svelte to filter items interactively
B. Render an empty list and fetch items only after JavaScript loads
C. Hide the list and show it only after the filter button is clicked
D. Use only JavaScript to create and display the list dynamically

Solution

  1. Step 1: Understand progressive enhancement for lists

    Start with a fully rendered list in HTML so users without JS see all items.
  2. Step 2: Add interactive filtering with Svelte

    Use Svelte to add filtering on top, enhancing the experience for JS users.
  3. Final Answer:

    Render the full list in HTML first, then use Svelte to filter items interactively -> Option A
  4. Quick Check:

    Basic content first, then interactive features [OK]
Hint: Show full content first, then add JS filters [OK]
Common Mistakes:
  • Loading list only after JS runs
  • Hiding content initially
  • Relying solely on JS for content display
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard