-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator4.html
More file actions
53 lines (43 loc) · 1.4 KB
/
calculator4.html
File metadata and controls
53 lines (43 loc) · 1.4 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
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>문자열 계산기 구현하기</h1>
<div id="output"></div>
<script>
function main(){
var n1 = Number(prompt("첫번째 숫자를 입력해 주세요."));
var out = document.getElementById('output');
var op, n2;
var result = n1;
var n = 2;
while(true){
op = prompt("연산자를 입력해 주세요.");
if (op === 'q'){
break;
}
n2 = Number(prompt(n + "번째 숫자를 입력해 주세요."));
if (op === '+'){
result += n2;
}else if(op === '-'){
result -= n2;
}else if(op === '*'){
result *= n2;
}else if(op === '/'){
result /= n2;
}else {
result = "중간오류";
break;
}
n++;
}
out.innerHTML = "최종결과값은 " + result + " 입니다.";
}
main();
</script>
</body>
</html>