gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Hello
- User
Hello
- Assistant
Hello! How can I assist you today?
- User
Make a html calculaor
- Assistant
Creating a simple HTML calculator involves combining HTML for the structure, CSS for styling, and JavaScript for functionality. Below is a basic example of a calculator:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Simple Calculator</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f4f4f4; } .calculator { border-radius: 10px; overflow: hidden; box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1); width: 300px; background-color: #fff; } .display { background-color: #222; color: #fff; text-align: right; padding: 10px; font-size: 2em; } .keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; } button { font-size: 1.5em; padding: 20px; border: none; cursor: pointer; background-color: #eaeaea; } button:hover { background-color: #d1d1d1; } .operator { background-color: #f1a33c; color: #fff; } .operator:hover { background-color: #f1910c; } .equal { background-color: #4CAF50; color: #fff; grid-column: span 4; } .equal:hover { background-color: #45a049; } </style> </head> <body> <div class="calculator"> <div class="display" id="display">0</div> <div class="keys"> <button class="operator" onclick="appendOperator('+')">+</button> <button class="operator" onclick="appendOperator('-')">-</button> <button class="operator" onclick="appendOperator('*')">*</button> <button class="operator" onclick="appendOperator('/')">/</button> <button onclick="appendNumber('7')">7</button> <button onclick="appendNumber('8')">8</button> <button onclick="appendNumber('9')">9</button> <button onclick="clearDisplay()">C</button> <button onclick="appendNumber('4')">4</button> <button onclick="appendNumber('5')">5</button> <button onclick="appendNumber('6')">6</button> <button onclick="backspace()">⌫</button> <button onclick="appendNumber('1')">1</button> <button onclick="appendNumber('2')">2</button> <button onclick="appendNumber('3')">3</button> <button onclick="appendDecimal()">.</button> <button onclick="appendNumber('0')">0</button> <button class="equal" onclick="calculate()">=</button> </div> </div> <script> let display = document.getElementById('display'); let currentInput = '0'; function appendNumber(number) { if (currentInput === '0') { currentInput = number; } else { currentInput += number; } updateDisplay(); } function appendOperator(operator) { if (!isNaN(currentInput[currentInput.length - 1])) { currentInput += ` ${operator} `; } updateDisplay(); } function appendDecimal() { if (!currentInput.includes('.')) { currentInput += '.'; } updateDisplay(); } function calculate() { try { currentInput = eval(currentInput.replace(/×/g, '*').replace(/÷/g, '/')).toString(); } catch { currentInput = 'Error'; } updateDisplay(); } function clearDisplay() { currentInput = '0'; updateDisplay(); } function backspace() { currentInput = currentInput.slice(0, -1); if (currentInput === '') { currentInput = '0'; } updateDisplay(); } function updateDisplay() { display.textContent = currentInput; } </script> </body> </html>Explanation:
- HTML: This creates the structure, with buttons for numbers, operators, and actions like clear and backspace.
- CSS: Provides a basic style for a better user experience.
- JavaScript: Handles the logic for typing numbers, performing calculations, and displaying results.
This calculator allows basic operations such as addition, subtraction, multiplication, and division. You can expand upon it by adding functionality for more complex operations and improving error handling.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
claude-instant-1Compare side by side →