일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- mac terminal command
- #android activity
- 토큰경제
- #binary
- border-box
- html charset
- #C++ 연산자함수오버로딩
- #자바상속#자바이즈어#is~a
- #CallByAddress
- git flow
- #2차원배열
- #성적관리프로그램
- html object
- #3차원배열
- #bubbleSort
- html youtube
- #1차원배열
- html id
- html plug-in
- html5 new tag
- hyperledger transaction
- #C++ has~a
- relative path
- html video
- docker example
- html code
- html multimedia
- 하이퍼레저패브릭
- #다차원포인터
- #JAVASCRIPT
Archives
- Today
- Total
A sentimental robot
Calculator ver.2 본문
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 |
<html>
<head>
<title>cal</title>
<script language="javascript">
// 버튼을 누르면 버튼 값이 들어간다.
function input(num){
var text=document.getElementById("text");
text.value+=num;
}
// clear onclick 함수
function cl(){
text.value="";
}
// 결과 값을 보여준다.
function showResult(){
// indexOf는 해당 문자의 위치 값을 int로 리턴한다.
if(text.value.indexOf('^')>0){ // x,y필요하기 때문에 ^는 0자리보다 크다.
var p=text.value.split('^');
text.value=Math.pow(parseInt(p[0]),parseInt(p[1]));
}
else if(text.value.indexOf('s')==0) // sin,cos,tan는 맨처음 위치해있기 때문에 == 0
{
var s=text.value.split('s');
var sr=Math.sin(parseInt(s[1]));
text.value=sr;
}else if(text.value.indexOf('c')==0){
var c=text.value.split('c');
var cr=Math.sin(parseInt(c[1]));
text.value=cr;
}else if(text.value.indexOf('t')==0){
var t=text.value.split('t');
var tr=Math.sin(parseInt(t[1]));
text.value=tr;
}
else {
//eval는 문자열 식을 그대로 계산해준다.
var r=eval(text.value.toString());
text.value=r;
}
}
function m(){
if(Math.sign(text.value)==1){ // 숫자가 양수이면 1 return
text.value='-'+text.value;
}
else { // 음수이면 -1 return
text.value=Math.abs(text.value); // 음수일때 절대값으로 바꿔주기
}
}
</script>
</head>
<body>
<!-- 테이블 -->
<table border="0" align="center">
<tr>
<!-- 1행-->
<td colspan="5" align="center"> <input type="text" id="text"></td>
</tr>
<tr>
<!-- 2행 -->
<td colspan="3" align="center"><input type="button" value="Clear" onclick="cl()" style="backgroundcolor:white;color:darkblue;width:100px;
height:20px;"></td>
<td colspan="2" align="center"><input type="button" value="=" id="equal" onclick="showResult()" style="backgroundcolor:white;color:darkblue;width:100px;
height:20px;"></td>
</tr>
<tr>
<td><input type="button" value="1" id="1" onclick="input(1)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="2" id="2" onclick="input(2)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="3" id="3" onclick="input(3)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="+" id="plus" onclick="input('+')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
<td><input type="button" value="x^y" id="xy" onclick="input('^')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
</tr>
<tr>
<td><input type="button" value="4" id="four" onclick="input(4)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="5" id="five" onclick="input(5)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="6" id="six" onclick="input(6)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="-" id="min" onclick="input('-')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
<td><input type="button" value="sin" id="sin" onclick="input('s')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
</tr>
<tr>
<td><input type="button" value="7" id="seven" onclick="input(7)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="8" id="eight" onclick="input(8)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="9" id="nine" onclick="input(9)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="*" id="mul" onclick="input('*')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
<td><input type="button" value="cos" id="cos" onclick="input('c')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
</tr>
<tr>
<td><input type="button" value="0" id="zero" onclick="input(0)" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td align="center"><input type="button" value="+/-" id="pm" onclick="m()" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="." id="dot" onclick="input('.')" style="backgroundcolor:white;color:darkblue;width:30px;
height:20px;"></td>
<td><input type="button" value="/" id="divide" onclick="input('/')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
<td><input type="button" value="tan" id="tan" onclick="input('t')" style="backgroundcolor:white;color:darkblue;width:50px;
height:20px;"></td>
</tr>
</table>
</body>
</html>
|
cs |
'Web' 카테고리의 다른 글
Background color (0) | 2018.10.19 |
---|---|
Javascript Array (0) | 2018.10.19 |
Javascript ex2 (0) | 2018.10.18 |
Javascript ex1 (0) | 2018.10.17 |
HTML 회원가입 (0) | 2018.10.17 |