make a beautiful calculator
- User
make a beautiful 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.
make a beautiful calculator
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a sleek, modern calculator design 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>
:root {
--primary-color: #6c5ce7;
--secondary-color: #a29bfe;
--accent-color: #fd79a8;
--text-color: #2d3436;
--bg-color: #f5f6fa;
--button-shadow: 0 4px 0 #dfe6e9;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
.calculator {
width: 320px;
background-color: white;
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
overflow: hidden;
padding: 20px;
}
.display {
background-color: var(--bg-color);
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
text-align: right;
font-size: 2.5rem;
height: 80px;
display: flex;
flex-direction: column;
justify-content: flex-end;
color: var(--text-color);
overflow: hidden;
}
.previous-operand {
font-size: 1.2rem;
color: rgba(0, 0, 0, 0.5);
height: 24px;
overflow: hidden;
}
.current-operand {
font-size: 2.5rem;
overflow: hidden;
text-overflow: ellipsis;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 10px;
}
button {
border: none;
border-radius: 50%;
height: 60px;
width: 60px;
font-size: 1.5rem;
cursor: pointer;
transition: all 0.2s;
background-color: white;
color: var(--text-color);
box-shadow: var(--button-shadow);
display: flex;
justify-content: center;
align-items: center;
}
button:active {
transform: translateY(4px);
box-shadow: none;
}
button:not(:active) {
transform: translateY(0);
}
.span-2 {
grid-column: span 2;
border-radius: 30px;
width: auto;
}
.operator {
background-color: var(--secondary-color);
color: white;
}
.equals {
background-color: var(--accent-color);
color: white;
}
.clear, .delete {
background-color: var(--primary-color);
color: white;
}
.clear {
background-color: #ff7675;
}
.delete {
background-color: #fdcb6e;
}
</style>
</head>
<body>
<div class="calculator">
<div class="display">
<div class="previous-operand"></div>
<div class="current-operand">0</div>
</div>
<div class="buttons">
<button class="clear">AC</button>
<button class="delete">DEL</button>
<button class="operator">÷</button>
<button class="operator">×</button>
<button>7</button>
<button>8</button>
<button>9</button>
<button class="operator">-</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button class="operator">+</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button class="equals span-2">=</button>
<button>0</button>
<button>.</button>
</div>
</div>
<script>
class Calculator {
constructor(previousOperandTextElement, currentOperandTextElement) {
this.previousOperandTextElement = previousOperandTextElement;
this.currentOperandTextElement = currentOperandTextElement;
this.clear();
}
clear() {
this.currentOperand = '0';
this.previousOperand = '';
this.operation = undefined;
}
delete() {
this.currentOperand = this.currentOperand.toString().slice(0, -1);
if (this.currentOperand === '') {
this.currentOperand = '0';
}
}
appendNumber(number) {
if (number === '.' && this.currentOperand.includes('.')) return;
if (this.currentOperand === '0' && number !== '.') {
this.currentOperand = number.toString();
} else {
this.currentOperand = this.currentOperand.toString() + number.toString();
}
}
chooseOperation(operation) {
if (this.currentOperand === '') return;
if (this.previousOperand !== '') {
this.compute();
}
this.operation = operation;
this.previousOperand = this.currentOperand;
this.currentOperand = '';
}
compute() {
let computation;
const prev = parseFloat(this.previousOperand);
const current = parseFloat(this.currentOperand);
if (isNaN(prev) || isNaN(current)) return;
switch (this.operation) {
case '+':
computation = prev + current;
break;
case '-':
computation = prev - current;
break;
case '×':
computation = prev * current;
break;
case '÷':
computation = prev / current;
break;
default:
return;
}
this.currentOperand = computation.toString();
this.operation = undefined;
this.previousOperand = '';
}
updateDisplay() {
this.currentOperandTextElement.innerText = this.currentOperand;
if (this.operation != null) {
this.previousOperandTextElement.innerText =
`${this.previousOperand} ${this.operation}`;
} else {
this.previousOperandTextElement.innerText = '';
}
}
}
const numberButtons = document.querySelectorAll('button:not(.operator):not(.clear):not(.delete):not(.equals)');
const operatorButtons = document.querySelectorAll('.operator');
const equalsButton = document.querySelector('.equals');
const deleteButton = document.querySelector('.delete');
const clearButton = document.querySelector('.clear');
const previousOperandTextElement = document.querySelector('.previous-operand');
const currentOperandTextElement = document.querySelector('.current-operand');
const calculator = new Calculator(previousOperandTextElement, currentOperandTextElement);
numberButtons.forEach(button => {
button.addEventListener('click', () => {
calculator.appendNumber(button.innerText);
calculator.updateDisplay();
});
});
operatorButtons.forEach(button => {
button.addEventListener('click', () => {
calculator.chooseOperation(button.innerText);
calculator.updateDisplay();
});
});
equalsButton.addEventListener('click', () => {
calculator.compute();
calculator.updateDisplay();
});
clearButton.addEventListener('click', () => {
calculator.clear();
calculator.updateDisplay();
});
deleteButton.addEventListener('click', () => {
calculator.delete();
calculator.updateDisplay();
});
</script>
</body>
</html>
Modern Design:
Functionality:
User Experience:
Visual Elements:
You can copy this code into an HTML file and open it in any modern browser to use the calculator. The design is both functional and aesthetically pleasing.