-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.html
More file actions
36 lines (33 loc) · 1022 Bytes
/
Example3.html
File metadata and controls
36 lines (33 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<style>
#result {
color: blue;
}
</style>
</head>
<body>
<h2>Simple Calculator</h2>
<input type="text" id="klu" placeholder="Enter expression">
<button onclick="calculate()">=</button>
<button onclick="clearDisplay()">Clear</button>
<h1 id="result"></h1>
<script>
function calculate() {
try {
const expr = document.getElementById('klu').value;
const output = eval(expr);
document.getElementById('result').textContent = output;
} catch {
document.getElementById('result').textContent = 'Error';
}
}
function clearDisplay() {
document.getElementById('klu').value = "";
document.getElementById('result').textContent = "";
}
</script>
</body>
</html>