@@ -3,10 +3,106 @@ let operation = null;
33
44const inputWindow = document . getElementById ( 'inputWindow' ) ;
55
6+ // ЧИСЛА
7+ document . getElementById ( 'btn_1' ) . addEventListener ( 'click' , function ( ) {
8+ inputWindow . value += '1' ;
9+ } )
10+
11+ document . getElementById ( 'btn_2' ) . addEventListener ( 'click' , function ( ) {
12+ inputWindow . value += '2' ;
13+ } )
14+
15+ document . getElementById ( 'btn_3' ) . addEventListener ( 'click' , function ( ) {
16+ inputWindow . value += '3' ;
17+ } )
18+
19+ document . getElementById ( 'btn_4' ) . addEventListener ( 'click' , function ( ) {
20+ inputWindow . value += '4' ;
21+ } )
22+
23+ document . getElementById ( 'btn_5' ) . addEventListener ( 'click' , function ( ) {
24+ inputWindow . value += '5' ;
25+ } )
26+
27+ document . getElementById ( 'btn_6' ) . addEventListener ( 'click' , function ( ) {
28+ inputWindow . value += '6' ;
29+ } )
30+
31+ document . getElementById ( 'btn_7' ) . addEventListener ( 'click' , function ( ) {
32+ inputWindow . value += '7' ;
33+ } )
34+
35+ document . getElementById ( 'btn_8' ) . addEventListener ( 'click' , function ( ) {
36+ inputWindow . value += '8' ;
37+ } )
638
39+ document . getElementById ( 'btn_9' ) . addEventListener ( 'click' , function ( ) {
40+ inputWindow . value += '9' ;
41+ } )
42+
43+ document . getElementById ( 'btn_0' ) . addEventListener ( 'click' , function ( ) {
44+ inputWindow . value += '0' ;
45+ } )
46+
47+
48+ // ОПЕРАЦИИ
49+
50+ // сложение
51+ document . getElementById ( 'btn_sum' ) . addEventListener ( 'click' , function ( ) {
52+ lastOperand = parseInt ( inputWindow . value ) ;
53+ operation = 'sum' ;
54+ inputWindow . value = '' ;
55+ } )
56+ // вычитание
57+ document . getElementById ( 'btn_def' ) . addEventListener ( 'click' , function ( ) {
58+ lastOperand = parseInt ( inputWindow . value ) ;
59+ operation = 'def' ;
60+ inputWindow . value = '' ;
61+ } )
62+ // умножение
63+ document . getElementById ( 'btn_mult' ) . addEventListener ( 'click' , function ( ) {
64+ lastOperand = parseInt ( inputWindow . value ) ;
65+ operation = 'mult' ;
66+ inputWindow . value = '' ;
67+ } )
68+ // деление
69+ document . getElementById ( 'btn_div' ) . addEventListener ( 'click' , function ( ) {
70+ lastOperand = parseInt ( inputWindow . value ) ;
71+ operation = 'div' ;
72+ inputWindow . value = '' ;
73+ } )
74+ // равно
75+ document . getElementById ( 'btn_calc' ) . addEventListener ( 'click' , function ( ) {
76+ if ( operation === 'sum' ) {
77+ const result = lastOperand + parseInt ( inputWindow . value ) ;
78+ operation = null ;
79+ lastOperand = 0 ;
80+ inputWindow . value = result ;
81+ }
82+ if ( operation === 'def' ) {
83+ const result = lastOperand - parseInt ( inputWindow . value ) ;
84+ operation = null ;
85+ lastOperand = 0 ;
86+ inputWindow . value = result ;
87+ }
88+ if ( operation === 'mult' ) {
89+ const result = lastOperand * parseInt ( inputWindow . value ) ;
90+ operation = null ;
91+ lastOperand = 0 ;
92+ inputWindow . value = result ;
93+ }
94+ if ( operation === 'div' ) {
95+ const result = lastOperand / parseInt ( inputWindow . value ) ;
96+ operation = null ;
97+ lastOperand = 0 ;
98+ inputWindow . value = result ;
99+ }
100+ } )
101+ // очистить
7102document . getElementById ( 'btn_clr' ) . addEventListener ( 'click' , function ( ) {
8103 lastOperand = 0 ;
9104 operation = null ;
10105 inputWindow . value = '' ;
11106} )
12107
108+
0 commit comments