Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-v3-0324· DeepSeekHugging Face LMArena Human Preference 140K

Write a basic svelte 5 counter component

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with MiniMaxminimax-m1’s answer.
  1. User

    Write a basic svelte 5 counter component

  2. DeepSeek Assistant

    Svelte 5 Counter Component

    Here's a basic counter component in Svelte 5 using the new Runes syntax:

    <script>
        let count = $state(0);
    
        function increment() {
            count += 1;
        }
    
        function decrement() {
            count -= 1;
        }
    
        function reset() {
            count = 0;
        }
    </script>
    
    <div class="counter">
        <h1>Counter: {count}</h1>
        
        <div class="buttons">
            <button on:click={decrement}>-</button>
            <button on:click={reset}>Reset</button>
            <button on:click={increment}>+</button>
        </div>
    </div>
    
    <style>
        .counter {
            text-align: center;
            font-family: Arial, sans-serif;
            max-width: 300px;
            margin: 0 auto;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
        
        h1 {
            color: #333;
        }
        
        .buttons {
            display: flex;
            gap: 10px;
            justify-content: center;
        }
        
        button {
            padding: 8px 16px;
            font-size: 16px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
        }
        
        button:hover {
            background-color: #45a049;
        }
    </style>
    

    Key Features:

    1. Uses Svelte 5's $state rune to create reactive state
    2. Includes increment, decrement, and reset functionality
    3. Basic styling for a clean look
    4. Simple, component-scoped CSS
    5. Follows Svelte's component structure (script, markup, style)

    You can use this component in your Svelte 5 application by importing it where needed. The counter state is fully reactive and will update the UI automatically when changed.

    Note: This assumes you're using Svelte 5 with Runes enabled. If you're using an older version of Svelte, you would need to adapt the state management syntax.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.