Skip to content
The Chat Archive
claude-opus-4-20250514· Anthropic LMArena Human Preference 140K

make a beautiful calculator

  1. User

    make a beautiful calculator

  2. Assistant

    I'll create a beautiful calculator with a modern, clean design. Here's a fully functional calculator with HTML, CSS, and JavaScript:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Beautiful Calculator</title>
        <style>
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }
    
            body {
                font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                min-height: 100vh;
                display: flex;
                justify-content: center;
                align-items: center;
                padding: 20px;
            }
    
            .calculator {
                background: rgba(255, 255, 255, 0.95);
                border-radius: 20px;
                padding: 30px;
                box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
                backdrop-filter: blur(10px);
                max-width: 400px;
                width: 100%;
            }
    
            .display {
                background: #f0f0f0;
                border-radius: 10px;
                padding: 20px;
                margin-bottom: 20px;
                text-align: right;
                min-height: 80px;
                display: flex;
                flex-direction: column;
                justify-content: center;
            }
    
            .previous-operand {
                color: #666;
                font-size: 18px;
                min-height: 24px;
            }
    
            .current-operand {
                color: #333;
                font-size: 36px;
                font-weight: 500;
                word-wrap: break-word;
                word-break: break-all;
            }
    
            .buttons {
                display: grid;
                grid-template-columns: repeat(4, 1fr);
                gap: 15px;
            }
    
            button {
                border: none;
                border-radius: 10px;
                font-size: 20px;
                padding: 20px;
                cursor: pointer;
                transition: all 0.3s ease;
                font-weight: 500;
            }
    
            button:hover {
                transform: translateY(-2px);
                box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            }
    
            button:active {
                transform: translateY(0);
            }
    
            .number {
                background: #e0e0e0;
                color: #333;
            }
    
            .number:hover {
                background: #d0d0d0;
            }
    
            .operator {
                background: #667eea;
                color: white;
            }
    
            .operator:hover {
                background: #5a67d8;
            }
    
            .equals {
                background: #48bb78;
                color: white;
                grid-column: span 2;
            }
    
            .equals:hover {
                background: #38a169;
            }
    
            .clear {
                background: #f56565;
                color: white;
            }
    
            .clear:hover {
                background: #e53e3e;
            }
    
            .delete {
                background: #ed8936;
                color: white;
            }
    
            .delete:hover {
                background: #dd6b20;
            }
    
            .zero {
                grid-column: span 2;
            }
        </style>
    </head>
    <body>
        <div class="calculator">
            <div class="display">
                <div class="previous-operand" id="previousOperand"></div>
                <div class="current-operand" id="currentOperand">0</div>
            </div>
            <div class="buttons">
                <button class="clear" onclick="clearAll()">AC</button>
                <button class="delete" onclick="deleteLast()">DEL</button>
                <button class="operator" onclick="chooseOperation('÷')">÷</button>
                <button class="operator" onclick="chooseOperation('×')">×</button>
                
                <button class="number" onclick="appendNumber('7')">7</button>
                <button class="number" onclick="appendNumber('8')">8</button>
                <button class="number" onclick="appendNumber('9')">9</button>
                <button class="operator" onclick="chooseOperation('-')">-</button>
                
                <button class="number" onclick="appendNumber('4')">4</button>
                <button class="number" onclick="appendNumber('5')">5</button>
                <button class="number" onclick="appendNumber('6')">6</button>
                <button class="operator" onclick="chooseOperation('+')">+</button>
                
                <button class="number" onclick="appendNumber('1')">1</button>
                <button class="number" onclick="appendNumber('2')">2</button>
                <button class="number" onclick="appendNumber('3')">3</button>
                <button class="number" onclick="appendNumber('.')">.</button>
                
                <button class="number zero" onclick="appendNumber('0')">0</button>
                <button class="equals" onclick="compute()">=</button>
            </div>
        </div>
    
        <script>
            let currentOperand = '0';
            let previousOperand = '';
            let operation = null;
    
            const currentOperandDisplay = document.getElementById('currentOperand');
            const previousOperandDisplay = document.getElementById('previousOperand');
    
            function updateDisplay() {
                currentOperandDisplay.textContent = currentOperand;
                if (operation != null) {
                    previousOperandDisplay.textContent = `${previousOperand} ${operation}`;
                } else {
                    previousOperandDisplay.textContent = previousOperand;
                }
            }
    
            function clearAll() {
                currentOperand = '0';
                previousOperand = '';
                operation = null;
                updateDisplay();
            }
    
            function deleteLast() {
                if (currentOperand === '0') return;
                if (currentOperand.length === 1) {
                    currentOperand = '0';
                } else {
                    currentOperand = currentOperand.slice(0, -1);
                }
                updateDisplay();
            }
    
            function appendNumber(number) {
                if (number === '.' && currentOperand.includes('.')) return;
                if (currentOperand === '0' && number !== '.') {
                    currentOperand = number;
                } else {
                    currentOperand += number;
                }
                updateDisplay();
            }
    
            function chooseOperation(op) {
                if (currentOperand === '') return;
                if (previousOperand !== '') {
                    compute();
                }
                operation = op;
                previousOperand = currentOperand;
                currentOperand = '0';
                updateDisplay();
            }
    
            function compute() {
                let computation;
                const prev = parseFloat(previousOperand);
                const current = parseFloat(currentOperand);
                if (isNaN(prev) || isNaN(current)) return;
    
                switch (operation) {
                    case '+':
                        computation = prev + current;
                        break;
                    case '-':
                        computation = prev - current;
                        break;
                    case '×':
                        computation = prev * current;
                        break;
                    case '÷':
                        if (current === 0) {
                            alert("Cannot divide by zero!");
                            return;
                        }
                        computation = prev / current;
                        break;
                    default:
                        return;
                }
    
                currentOperand = computation.toString();
                operation = null;
                previousOperand = '';
                updateDisplay();
            }
    
            // Keyboard support
            document.addEventListener('keydown', (e) => {
                if (e.key >= '0' && e.key <= '9') appendNumber(e.key);
                if (e.key === '.') appendNumber('.');
                if (e.key === '+') chooseOperation('+');
                if (e.key === '-') chooseOperation('-');
                if (e.key === '*') chooseOperation('×');
                if (e.key === '/') {
                    e.preventDefault();
                    chooseOperation('÷');
                }
                if (e.key === 'Enter' || e.key === '=') compute();
                if (e.key === 'Escape') clearAll();
                if (e.key === 'Backspace') deleteLast();
            });
        </script>
    </body>
    </html>
    

    This calculator features:

    • Modern Design: Clean, minimalist interface with a gradient background and glassmorphism effect
    • Smooth Animations: Hover effects and button press animations
    • Full Functionality: Basic arithmetic operations (addition, subtraction, multiplication, division)
    • Keyboard Support: Use your keyboard for all operations
    • Responsive Design: Works well on different screen sizes
    • Error Handling: Prevents division by zero
    • Visual Feedback: Shows previous operation and current number

    The calculator uses a purple gradient background with a semi-transparent white container, creating a modern and elegant look. The buttons have different colors based on their function - numbers are gray, operators are purple, equals is green, clear is red, and delete is orange.

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