Cal 2
Cal 2
Verify
Open In Editor
Edit
Run
Copy code
<!DOCTYPE html>
<html>
<head>
<title>HTML Calculator</title>
<style>
/* Add some basic styling to our calculator */
.calculator {
width: 200px;
margin: 50px auto;
padding: 20px;
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.calculator input[type="text"] {
width: 100%;
height: 40px;
margin-bottom: 10px;
padding: 10px;
font-size: 18px;
border: 1px solid #ccc;
}
.calculator input[type="button"] {
width: 45%;
height: 40px;
margin: 10px 5px;
padding: 10px;
font-size: 18px;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: #fff;
cursor: pointer;
}
.calculator input[type="button"]:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<input type="button" value="7" onclick="press(7)">
<input type="button" value="8" onclick="press(8)">
<input type="button" value="9" onclick="press(9)">
<input type="button" value="/" onclick="press('/')">
<br>
<input type="button" value="4" onclick="press(4)">
<input type="button" value="5" onclick="press(5)">
<input type="button" value="6" onclick="press(6)">
<input type="button" value="*" onclick="press('*')">
<br>
<input type="button" value="1" onclick="press(1)">
<input type="button" value="2" onclick="press(2)">
<input type="button" value="3" onclick="press(3)">
<input type="button" value="-" onclick="press('-')">
<br>
<input type="button" value="0" onclick="press(0)">
<input type="button" value="C" onclick="clearDisplay()">
<input type="button" value="=" onclick="calculate()">
<input type="button" value="+" onclick="press('+')">
</div>
<script>
// Get the display element
let display = document.getElementById('display');