0% found this document useful (0 votes)
16 views3 pages

!doctype HTML

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

!doctype HTML

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<!

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;
margin: 0;
background-color: #f4f4f9;
}
.calculator {
width: 280px;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.display {
width: 100%;
height: 50px;
background-color: #f1f1f1;
border: none;
font-size: 24px;
text-align: right;
padding: 10px;
box-sizing: border-box;
margin-bottom: 20px;
}
.button-row {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.button {
width: 60px;
height: 60px;
font-size: 20px;
background-color: #f1f1f1;
border: 1px solid #ddd;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: background-color 0.2s;
}
.button:hover {
background-color: #ddd;
}
.button:active {
background-color: #ccc;
}
.equal {
background-color: #4CAF50;
color: white;
}
.clear {
background-color: #f44336;
color: white;
}
</style>
</head>
<body>

<div class="calculator">
<input type="text" id="display" class="display" disabled>
<div class="button-row">
<button class="button" onclick="appendToDisplay('7')">7</button>
<button class="button" onclick="appendToDisplay('8')">8</button>
<button class="button" onclick="appendToDisplay('9')">9</button>
<button class="button" onclick="appendToDisplay('/')">/</button>
</div>
<div class="button-row">
<button class="button" onclick="appendToDisplay('4')">4</button>
<button class="button" onclick="appendToDisplay('5')">5</button>
<button class="button" onclick="appendToDisplay('6')">6</button>
<button class="button" onclick="appendToDisplay('*')">*</button>
</div>
<div class="button-row">
<button class="button" onclick="appendToDisplay('1')">1</button>
<button class="button" onclick="appendToDisplay('2')">2</button>
<button class="button" onclick="appendToDisplay('3')">3</button>
<button class="button" onclick="appendToDisplay('-')">-</button>
</div>
<div class="button-row">
<button class="button" onclick="appendToDisplay('0')">0</button>
<button class="button" onclick="appendToDisplay('.')">.</button>
<button class="button clear" onclick="clearDisplay()">C</button>
<button class="button" onclick="appendToDisplay('+')">+</button>
</div>
<div class="button-row">
<button class="button equal" onclick="calculate()">=</button>
</div>
</div>

<script>
function appendToDisplay(value) {
document.getElementById('display').value += value;
}

function clearDisplay() {
document.getElementById('display').value = '';
}

function calculate() {
const display = document.getElementById('display');
try {
display.value = eval(display.value);
} catch (e) {
display.value = 'Error';
}
}
</script>

</body>
</html>

You might also like