(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-8242763509535969", enable_page_level_ads: true }); [자바스크립트] 계산기 :: 깜냥깜냥

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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>계산기</title>
<style type="text/css">
.button1 {
    background-Color: #FFC5D0; /*--백그라운드 정의---*/
    font: 12px; /*--폰트 정의---*/
    font-weight: bold; /*--폰트 굵기---*/
    color: #8FFFE0; /*--폰트 색깔---*/
}
 
.button2 {
    background-Color: #FFB78F;
    font: 12px;
    color: #FAD4DC;
}
 
.button3 {
    background-Color: #FFCFB5;
    font: 12px;
    color: #9B558E;
}
 
.button4 {
    background-Color: #D2ECC4;
    font: 12px;
    color: #50917D;
}
</style>
<script language="javascript">
    function num(chr) {
        var input = document.getElementById("display");
        if (input.value == null || input.value == "0") {
            input.value = chr;
        } else {
            input.value += chr;
        }
        return input.value
    }
 
    function deletee(input) {
        input.value = input.value.substring(0, input.value.length - 1)
    }
 
    function pie(input) {
        input.value = eval(input.value) * PI
    }
 
    function change(input) {
        if (input.value.substring(0, 1) == "-")
            input.value = input.value.substring(1, input.value.length)
        else
            input.value = "-" + input.value
    }
    function sqrt(input) {
        input.value = Math.sqrt(input.value);
    }
    function tan(input) {
        input.value = Math.tan((input.value*3.141592)/180);
    }
    function sin(input) {
        input.value = Math.sin((input.value*3.141592)/180);
    }
    function cos(input) {
        input.value = Math.cos((input.value*3.141592)/180);
    }
    function log(input) {
        input.value = log(input.value)
    }
 
    function cal(input) {
        input.value = eval(input.value)
    }
    function square(input) {
        input.value = eval(input.value) * eval(input.value)
    }
</script>
</head>
<body marginheight="80">
    <form>
        <table align="center" width="150" height="250">
            <tr>
                <td align="center" colspan="6"><input type="text"
                    style="color: #72A1FF" id="display" size="20" value="0"></td>
            </tr>
            <tr>
                <td align="center" id="Clear" width="30"><input type="button"
                    value="C" size="40" maxlength="20" class="button1"
                    onClick="this.form.display.value = 0 "></td>
                <td align="center" id="result" colspan="2" width="30"><input type="button"
                    value="<-" class="button1" onclick="deletee(this.form.display)"></td>
                <td align="center" id="result" width="30"><input type="button"
                    value="=" class="button1" onclick="cal(this.form.display)"></td>
                <td align="center" width="30"><input type="button" id="root"
                    value="√" class="button4" onclick="sqrt(this.form.display)"></td>
                    
            </tr>
            <tr>
                <td align="center" width="30"><input type="button" value="1"
                    class="button2" onclick="num(1)"></td>
                <td align="center" width="30"><input type="button" value="2"
                    class="button2" onclick="num(2)"></td>
                <td align="center" width="30"><input type="button" value="3"
                    class="button2" onclick="num(3)"></td>
                <td align="center" width="30"><input type="button" value="+"
                    class="button3" onclick="num('+')"></td>
                <td align="center" width="30"><input type="button" value="x^2"
                    class="button4" onclick="square(this.form.display)"></td>
            </tr>
            <tr>
                <td align="center" width="30"><input type="button" value="4"
                    class="button2" onclick="num(4)"></td>
                <td align="center" width="30"><input type="button" value="5"
                    class="button2" onclick="num(5)"></td>
                <td align="center" width="30"><input type="button" value="6"
                    class="button2" onclick="num(6)"></td>
                <td align="center" width="30"><input type="button" value="-"
                    class="button3" onclick="num('-')"></td>
                <td align="center"><input type="button" value="sin"
                    class="button4" onclick="sin(this.form.display)"></td>
 
            </tr>
            <tr>
                <td align="center" width="30"><input type="button" value="7"
                    class="button2" onclick="num(7)"></td>
                <td align="center" width="30"><input type="button" value="8"
                    class="button2" onclick="num(8)"></td>
                <td align="center" width="30"><input type="button" value="9"
                    class="button2" onclick="num(9)"></td>
                <td align="center" width="30"><input type="button" value="*"
                    class="button3" onclick="num('*')"></td>
                <td align="center"><input type="button"value="cos"
                    class="button4" onclick="cos(this.form.display)"></td>
            </tr>
            <tr>
                <td align="center" width="30"><input type="button" id="pnnum"
                    value="+/-" class="button3" onclick="change(this.form.display)"></td>
                <td align="center" width="30"><input type="button" value="0"
                    class="button2" onclick="num(0)"></td>
                <td align="center" width="30"><input type="button" id="point"
                    value="." class="button3" onclick="num('.')"></td>
                <td align="center" width="30"><input type="button" value="/"
                    class="button3" onclick="num('/')"></td>
                <td align="center" width="30"><input type="button"
                    value="tan" class="button4" onclick="tan(this.form.display)"></td>
            </tr>
 
        </table>
    </form>
</body>
</html>

결과는 밑과 같이 나옵니다!




+ Recent posts