-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.html
More file actions
41 lines (35 loc) · 1008 Bytes
/
calc.html
File metadata and controls
41 lines (35 loc) · 1008 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
37
38
39
40
41
<body>
<input type="text" id="num1"/>
<select id="operations">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type="text" id="num2"/>
<input type="button" id="btn" value="계산"/>
<div id="result"></div>
</body>
<script>
let num1 = document.querySelector("#num1")
let num2 = document.querySelector("#num2")
let btn = document.querySelector("#btn")
let result = document.querySelector("#result")
let operations = document.querySelector("#operations")
btn.addEventListener("click", function(){
let a = parseInt(num1.value);
let b = parseInt(num2.value);
let r;
switch(operations.value){
case "+": r = a+b;
break;
case "-": r = a-b;
break;
case "*": r = a*b;
break;
case "/": r = a/b;
break;
}
result.innerText = r
});
</script>