Cal HTML
Cal HTML
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>
<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>
<br>
</body>
</html>