forked from hacktiv8/DevC-Exercise2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkalkulator.html
More file actions
43 lines (43 loc) · 1.36 KB
/
kalkulator.html
File metadata and controls
43 lines (43 loc) · 1.36 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Exercise 2</title>
</head>
<body>
<center>
<h1>Kalkulator</h1>
</center>
<input type="text" id="AngkaPertama">
<select id="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="x">*</option>
<option value="/">/</option>
</select>
<input type="text" id="AngkaKedua">
<input type="submit" onclick="kalkulator()" value="=">
<input type="text" id="hasil">
</body>
<script language="javascript" type="text/javascript">
function kalkulator() {
var AngkaPertama = parseInt(document.getElementById("AngkaPertama").value);
var AngkaKedua = parseInt(document.getElementById("AngkaKedua").value);
var op = document.getElementById("hasil");
var total;
if (isNaN(AngkaPertama) | isNaN(AngkaKedua)) {
alert("isi form dengan angka!!!!")
} else {
if (op == "+") {
total = AngkaPertama + AngkaKedua;
} else if (op == "-") {
total = AngkaPertama - AngkaKedua;
} else if (op == "x") {
total = AngkaPertama * AngkaKedua;
} else {
total = AngkaPertama / AngkaKedua;
}
}
hasil.value = total;
}
</script>
</html>