forked from domdorn/2025-01-27_graalvm_polyglot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
65 lines (63 loc) · 1.75 KB
/
index.html
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GraalVM Node.js Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f4f4f4;
}
.container {
margin-top: 50px;
padding: 20px;
background: white;
display: inline-block;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
input, button {
margin: 10px;
padding: 10px;
font-size: 16px;
}
#result {
font-size: 20px;
font-weight: bold;
color: green;
}
</style>
</head>
<body>
<div class="container">
<h2>Calculator</h2>
<input type="number" id="num1" placeholder="Enter first number">
<select id="operation">
<option value="add">+</option>
<option value="sub">-</option>
<option value="mult">×</option>
<option value="div">÷</option>
</select>
<input type="number" id="num2" placeholder="Enter second number">
<button onclick="calculate()">Calculate</button>
<p>Result: <span id="result">-</span></p>
</div>
<script>
function calculate() {
const num1 = document.getElementById("num1").value;
const num2 = document.getElementById("num2").value;
const operation = document.getElementById("operation").value;
fetch(`/api/calculate?op=${operation}&a=${num1}&b=${num2}`)
.then(response => response.json())
.then(data => {
document.getElementById("result").textContent = data.result ?? "Error";
})
.catch(error => {
document.getElementById("result").textContent = "Error";
});
}
</script>
</body>
</html>