I want html wyth calculator
- User
I want html wyth calculator
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
I want html wyth calculator
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure! Here's a simple HTML calculator with basic functionality (addition, subtraction, multiplication, and division) using HTML, CSS, and JavaScript:
You can copy this code into an .html file and open it in your browser to use the 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 {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
width: 260px;
}
.calculator input {
width: 100%;
font-size: 24px;
padding: 10px;
margin-bottom: 10px;
text-align: right;
box-sizing: border-box;
}
.calculator .buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
.calculator button {
padding: 20px;
font-size: 18px;
cursor: pointer;
border: none;
border-radius: 5px;
background-color: #e0e0e0;
transition: background 0.2s ease;
}
.calculator button:hover {
background-color: #d0d0d0;
}
.calculator button.operator {
background-color: #f9a825;
color: white;
}
.calculator button.equal {
background-color: #43a047;
color: white;
grid-column: span 2;
}
.calculator button.clear {
background-color: #e53935;
color: white;
grid-column: span 2;
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled />
<div class="buttons">
<button onclick="clearDisplay()" class="clear">C</button>
<button onclick="appendValue('(')">(</button>
<button onclick="appendValue(')')">)</button>
<button onclick="appendValue('/')" class="operator">÷</button>
<button onclick="appendValue('7')">7</button>
<button onclick="appendValue('8')">8</button>
<button onclick="appendValue('9')">9</button>
<button onclick="appendValue('*')" class="operator">×</button>
<button onclick="appendValue('4')">4</button>
<button onclick="appendValue('5')">5</button>
<button onclick="appendValue('6')">6</button>
<button onclick="appendValue('-')" class="operator">−</button>
<button onclick="appendValue('1')">1</button>
<button onclick="appendValue('2')">2</button>
<button onclick="appendValue('3')">3</button>
<button onclick="appendValue('+')" class="operator">+</button>
<button onclick="appendValue('0')">0</button>
<button onclick="appendValue('.')">.</button>
<button onclick="calculate()" class="equal">=</button>
</div>
</div>
<script>
const display = document.getElementById("display");
function appendValue(value) {
display.value += value;
}
function clearDisplay() {
display.value = "";
}
function calculate() {
try {
display.value = eval(display.value);
} catch (e) {
display.value = "Error";
}
}
</script>
</body>
</html>
+, -, *, /C) button=) evaluates expressionLet me know if you want:
I'm happy to help customize it further!