@@ -3,10 +3,173 @@ let operation = null;
33
44const inputWindow = document . getElementById ( 'inputWindow' ) ;
55
6+ inputWindow . value = '0' ;
67
7- document . getElementById ( 'btn_clr' ) . addEventListener ( 'click' , function ( ) {
8- lastOperand = 0 ;
9- operation = null ;
8+
9+ document . getElementById ( 'btn_1' ) . addEventListener ( 'click' , function ( ) {
10+ if ( inputWindow . value === '0' ) {
11+ inputWindow . value = '' ;
12+ }
13+ inputWindow . value += '1' ;
14+ } )
15+
16+ document . getElementById ( 'btn_2' ) . addEventListener ( 'click' , function ( ) {
17+ if ( inputWindow . value === '0' ) {
18+ inputWindow . value = '' ;
19+ }
20+ inputWindow . value += '2' ;
21+ } )
22+
23+ document . getElementById ( 'btn_3' ) . addEventListener ( 'click' , function ( ) {
24+ if ( inputWindow . value === '0' ) {
25+ inputWindow . value = '' ;
26+ }
27+ inputWindow . value += '3' ;
28+ } )
29+
30+ document . getElementById ( 'btn_4' ) . addEventListener ( 'click' , function ( ) {
31+ if ( inputWindow . value === '0' ) {
32+ inputWindow . value = '' ;
33+ }
34+ inputWindow . value += '4' ;
35+ } )
36+
37+ document . getElementById ( 'btn_5' ) . addEventListener ( 'click' , function ( ) {
38+ if ( inputWindow . value === '0' ) {
39+ inputWindow . value = '' ;
40+ }
41+ inputWindow . value += '5' ;
42+ } )
43+
44+ document . getElementById ( 'btn_6' ) . addEventListener ( 'click' , function ( ) {
45+ if ( inputWindow . value === '0' ) {
46+ inputWindow . value = '' ;
47+ }
48+ inputWindow . value += '6' ;
49+ } )
50+
51+ document . getElementById ( 'btn_7' ) . addEventListener ( 'click' , function ( ) {
52+ if ( inputWindow . value === '0' ) {
53+ inputWindow . value = '' ;
54+ }
55+ inputWindow . value += '7' ;
56+ } )
57+
58+ document . getElementById ( 'btn_8' ) . addEventListener ( 'click' , function ( ) {
59+ if ( inputWindow . value === '0' ) {
60+ inputWindow . value = '' ;
61+ }
62+ inputWindow . value += '8' ;
63+ } )
64+
65+ document . getElementById ( 'btn_9' ) . addEventListener ( 'click' , function ( ) {
66+ if ( inputWindow . value === '0' ) {
67+ inputWindow . value = '' ;
68+ }
69+ inputWindow . value += '9' ;
70+ } )
71+
72+ document . getElementById ( 'btn_0' ) . addEventListener ( 'click' , function ( ) {
73+ if ( inputWindow . value === '0' ) {
74+ inputWindow . value = '' ;
75+ }
76+ inputWindow . value += '0' ;
77+ } )
78+
79+ document . getElementById ( 'btn_sum' ) . addEventListener ( 'click' , function ( ) {
80+ lastOperand = parseInt ( inputWindow . value ) ;
81+ operation = 'sum' ;
82+ inputWindow . value = '' ;
83+ } )
84+
85+ document . getElementById ( 'btn_def' ) . addEventListener ( 'click' , function ( ) {
86+ lastOperand = parseInt ( inputWindow . value ) ;
87+ operation = 'def' ;
88+ inputWindow . value = '' ;
89+ } )
90+
91+ document . getElementById ( 'btn_mult' ) . addEventListener ( 'click' , function ( ) {
92+ lastOperand = parseInt ( inputWindow . value ) ;
93+ operation = 'mult' ;
94+ inputWindow . value = '' ;
95+ } )
96+
97+ document . getElementById ( 'btn_dev' ) . addEventListener ( 'click' , function ( ) {
98+ lastOperand = parseInt ( inputWindow . value ) ;
99+ operation = 'dev' ;
100+ inputWindow . value = '' ;
101+ } )
102+ document . getElementById ( 'btn_sqrt' ) . addEventListener ( 'click' , function ( ) {
103+ lastOperand = parseInt ( inputWindow . value ) ;
104+ operation = 'sqrt' ;
105+ inputWindow . value = '' ;
106+ if ( operation === 'sqrt' ) {
107+ const result = Math . sqrt ( lastOperand ) ;
108+ operation = null ;
109+ lastOperand = 0 ;
110+ inputWindow . value = result ;
111+ }
112+ } )
113+
114+ document . getElementById ( 'btn_unar' ) . addEventListener ( 'click' , function ( ) {
115+ lastOperand = parseInt ( inputWindow . value ) ;
116+ operation = 'unar' ;
117+ inputWindow . value = '' ;
118+
119+ if ( operation === 'unar' ) {
120+ const result = - lastOperand ;
121+ operation = null ;
122+ lastOperand = 0 ;
123+ inputWindow . value = result ;
124+ }
125+ } )
126+
127+ document . getElementById ( 'btn_point' ) . addEventListener ( 'click' , function ( ) {
128+ lastOperand = parseFloat ( inputWindow . value ) ;
129+ operation = 'point' ;
10130 inputWindow . value = '' ;
131+
132+ if ( operation === 'point' ) {
133+ const result = + inputWindow . value + '.' ;
134+ operation = null ;
135+ lastOperand = 0 ;
136+ inputWindow . value = result ;
137+ }
138+
11139} )
12140
141+ document . getElementById ( 'btn_calc' ) . addEventListener ( 'click' , function ( ) {
142+ if ( operation === 'sum' ) {
143+ const result = lastOperand + parseInt ( inputWindow . value ) ;
144+ operation = null ;
145+ lastOperand = 0 ;
146+ inputWindow . value = result ;
147+ }
148+
149+ if ( operation === 'def' ) {
150+ const result = lastOperand - parseFloat ( inputWindow . value ) ;
151+ operation = null ;
152+ lastOperand = 0 ;
153+ inputWindow . value = result ;
154+ }
155+
156+ if ( operation === 'mult' ) {
157+ const result = lastOperand * parseInt ( inputWindow . value ) ;
158+ operation = null ;
159+ lastOperand = 0 ;
160+ inputWindow . value = result ;
161+ }
162+
163+ if ( operation === 'dev' ) {
164+ const result = lastOperand / parseInt ( inputWindow . value ) ;
165+ operation = null ;
166+ lastOperand = 0 ;
167+ inputWindow . value = result ;
168+ }
169+ } )
170+
171+ document . getElementById ( 'btn_clr' ) . addEventListener ( 'click' , function ( ) {
172+ lastOperand = 0 ;
173+ operation = null ;
174+ inputWindow . value = '0' ;
175+ } )
0 commit comments