Create me a calculator in HTML and make it unique and make it the best calculator version available with all features
Creating a unique and feature-rich calculator in HTML, CSS, and JavaScript can be a fun project! Below is a simple yet effective calculator that includes basic arithmetic operations, a clear button, and a memory function. You can expand upon this foundation to add more features as needed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Unique Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<div class="buttons">
<button onclick="clearDisplay()">C</button>
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('/')">/</button>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="appendToDisplay('*')">*</button>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('-')">-</button>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="calculateResult()">=</button>
<button onclick="appendToDisplay('+')">+</button>
<button onclick="memoryStore()">M+</button>
<button onclick="memoryRecall()">MR</button>
<button onclick="memoryClear()">MC</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
.calculator {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 300px;
}
#display {
width: 100%;
height: 50px;
font-size: 24px;
text-align: right;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
padding: 10px;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
button {
padding: 20px;
font-size: 18px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
let memory = 0;
function appendToDisplay(value) {
document.getElementById('display').value += value;
}
function clearDisplay() {
document.getElementById('display').value = '';
}
function calculateResult() {
const display = document.getElementById('display');
try {
display.value = eval(display.value);
} catch (error) {
display.value = 'Error';
}
}
function memoryStore() {
memory = parseFloat(document.getElementById('display').value);
}
function memoryRecall() {
document.getElementById('display').value = memory;
}
function memoryClear() {
memory = 0;
}
index.html
, styles.css
, and script.js
.index.html
in a web browser to see your calculator in action.You can enhance this calculator by adding:
Feel free to modify and expand upon this code to make it your own!