<!
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;
text-align: center;
margin: 50px;
}
input[type="button"] {
width: 50px;
height: 50px;
font-size: 18px;
margin: 5px;
}
input[type="text"] {
width: 200px;
height: 50px;
font-size: 18px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h2>Simple Calculator</h2>
<input type="text" id="display" readonly>
<br>
<script>
function appendToDisplay(value) {
document.getElementById('display').value += value;
}
function clearDisplay() {
document.getElementById('display').value = '';
}
function calculate() {
try {
document.getElementById('display').value =
eval(document.getElementById('display').value);
} catch (error) {
document.getElementById('display').value = 'Error';
}
}
</script>
<input type="button" value="7" onclick="appendToDisplay('7')">
<input type="button" value="8" onclick="appendToDisplay('8')">
<input type="button" value="9" onclick="appendToDisplay('9')">
<input type="button" value="/" onclick="appendToDisplay('/')">
<br>
<input type="button" value="4" onclick="appendToDisplay('4')">
<input type="button" value="5" onclick="appendToDisplay('5')">
<input type="button" value="6" onclick="appendToDisplay('6')">
<input type="button" value="-" onclick="appendToDisplay('-')">
<br>
<input type="button" value="1" onclick="appendToDisplay('1')">
<input type="button" value="2" onclick="appendToDisplay('2')">
<input type="button" value="3" onclick="appendToDisplay('3')">
<input type="button" value="+" onclick="appendToDisplay('+')">
<br>
<input type="button" value="0" onclick="appendToDisplay('0')">
<input type="button" value="." onclick="appendToDisplay('.')">
<input type="button" value="C" onclick="clearDisplay()">
<input type="button" value="=" onclick="calculate()">
</body>
</html>