Fun Calculator
About this app
A fun, responsive calculator web app for all your mathematical needs.
Simple Calculator 0 C 7 8 9 / 4 5 6 * 1 2 3 - 0 = +
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Simple Calculator</title>
<meta name="description" content="A simple and fun calculator web app for basic mathematical operations.">
<meta name="keywords" content="calculator, simple, math, web app, fun">
<!-- Libraries -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.6.0/css/fontawesome.min.css" crossorigin="anonymous">
<script type="text/javascript">
try {
// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
let currentInput = '';
let operator = '';
let firstOperand = null;
const display = document.getElementById('display');
function updateDisplay() {
display.innerText = currentInput || '0';
}
function clearDisplay() {
currentInput = '';
operator = '';
firstOperand = null;
updateDisplay();
}
function calculate() {
if (firstOperand === null || operator === '' || currentInput === '') return;
const secondOperand = parseFloat(currentInput);
let result;
switch (operator) {
case '+':
result = firstOperand + secondOperand;
break;
case '-':
result = firstOperand - secondOperand;
break;
case '*':
result = firstOperand * secondOperand;
break;
case '/':
result = firstOperand / secondOperand;
break;
default:
return;
}
currentInput = result.toString();
operator = '';
firstOperand = null;
updateDisplay();
}
$('.number').click(function() {
currentInput += $(this).text();
updateDisplay();
});
$('.operator').click(function() {
if (currentInput === '') return;
if (firstOperand === null) {
firstOperand = parseFloat(currentInput);
} else {
calculate();
}
operator = $(this).text();
currentInput = '';
});
$('#equals').click(calculate);
$('#clear').click(clearDisplay);
});
} catch (error) {
throw error;
}
</script>
<style>
#main-container {
margin-top: 50px;
}
#calculator {
max-width: 400px;
margin: auto;
background: linear-gradient(135deg, #ff7675, #fdcb6e);
border-radius: 15px;
padding: 20px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
}
#display {
background: white;
font-size: 2em;
text-align: right;
padding: 10px;
border-radius: 10px;
margin-bottom: 20px;
}
button {
width: 60px;
height: 60px;
font-size: 1.5em;
margin: 5px;
border-radius: 10px;
border: none;
background: #fdcb6e;
transition: background 0.3s;
}
button:hover {
background: #e17055;
color: white;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<div id="calculator" class="p-4 rounded">
<div id="display">0</div>
<div class="d-flex flex-wrap justify-content-between">
<button id="clear">C</button>
<button class="number">7</button>
<button class="number">8</button>
<button class="number">9</button>
<button class="operator">/</button>
<button class="number">4</button>
<button class="number">5</button>
<button class="number">6</button>
<button class="operator">*</button>
<button class="number">1</button>
<button class="number">2</button>
<button class="number">3</button>
<button class="operator">-</button>
<button class="number">0</button>
<button id="equals">=</button>
<button class="operator">+</button>
</div>
</div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!