-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (25 loc) · 715 Bytes
/
script.js
File metadata and controls
28 lines (25 loc) · 715 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
function calculate() {
const angka1 = parseFloat(document.getElementById("number1").value);
const angka2 = parseFloat(document.getElementById("number2").value);
const operator = document.getElementById("operator").value;
let hasil;
switch (operator) {
case "+":
hasil = angka1 + angka2;
break;
case "-":
hasil = angka1 - angka2;
break;
case "*":
hasil = angka1 * angka2;
break;
case "/":
hasil = angka1 / angka2;
break;
default:
hasil = "Operator tidak valid";
}
document.getElementById("hasil").innerText = hasil;
}
const submitButton = document.getElementById("submit");
submitButton.addEventListener("click", calculate);