@@ -3,10 +3,144 @@ let operation = null;
33
44const inputWindow = document . getElementById ( 'inputWindow' ) ;
55
6+ // Кнопки Цифры с 0 до 9
7+ document . getElementById ( 'btn_1' ) . addEventListener ( 'click' , function ( ) {
8+ inputWindow . value += '1' ;
9+ } ) ;
610
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+ } ) ;
38+
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+ document . getElementById ( 'btn_clr' ) . addEventListener ( 'click' , function ( ) {
48+ lastOperand = 0 ;
49+ operation = null ;
50+ inputWindow . value = '' ;
51+ } ) ;
52+
53+ // Кнопка Суммы
54+ document . getElementById ( 'btn_sum' ) . addEventListener ( 'click' , function ( ) {
55+ lastOperand = parseInt ( inputWindow . value ) ;
56+ operation = 'sum' ;
57+ inputWindow . value = '' ;
58+ } ) ;
59+
60+ // Кнопка Разницы
61+ document . getElementById ( 'btn_diff' ) . addEventListener ( 'click' , function ( ) {
62+ lastOperand += parseInt ( inputWindow . value ) ;
63+ operation = 'diff' ;
64+ inputWindow . value = '' ;
65+ } ) ;
66+
67+ // Кнопка Умножения
68+ document . getElementById ( 'btn_mult' ) . addEventListener ( 'click' , function ( ) {
69+ lastOperand += parseInt ( inputWindow . value ) ;
70+ operation = 'mult' ;
71+ inputWindow . value = '' ;
72+ } ) ;
73+
74+ // Кнопка Деления
75+ document . getElementById ( 'btn_sep' ) . addEventListener ( 'click' , function ( ) {
76+ lastOperand += parseInt ( inputWindow . value ) ;
77+ operation = 'sep' ;
78+ inputWindow . value = '' ;
79+ } ) ;
80+
81+ // Кнопка Квадратного корня
82+ document . getElementById ( 'btn_sqrt' ) . addEventListener ( 'click' , function ( ) {
83+ lastOperand += parseInt ( inputWindow . value ) ;
84+ operation = 'sqrt' ;
85+ inputWindow . value = '' ;
86+ } ) ;
87+
88+
89+
90+ // Операция сложения
91+ document . getElementById ( 'btn_calc' ) . addEventListener ( 'click' , function ( ) {
92+ if ( operation === 'sum' ) {
93+ const result = lastOperand + parseInt ( inputWindow . value ) ;
94+ operation = null ;
95+ lastOperand = 0 ;
96+ inputWindow . value = result ;
97+ }
98+ } ) ;
99+
100+ // Операция разницы
101+ document . getElementById ( 'btn_calc' ) . addEventListener ( 'click' , function ( ) {
102+ if ( operation === 'diff' ) {
103+ const result = lastOperand - parseInt ( inputWindow . value ) ;
104+ operation = null ;
105+ lastOperand = 0 ;
106+ inputWindow . value = result ;
107+ }
108+ } ) ;
109+
110+ // Операция умножения
111+ document . getElementById ( 'btn_calc' ) . addEventListener ( 'click' , function ( ) {
112+ if ( operation === 'mult' ) {
113+ const result = lastOperand * parseInt ( inputWindow . value ) ;
114+ operation = null ;
115+ lastOperand = 0 ;
116+ inputWindow . value = result ;
117+ }
118+ } ) ;
119+
120+ // Операция деления
121+ document . getElementById ( 'btn_calc' ) . addEventListener ( 'click' , function ( ) {
122+ if ( operation === 'sep' ) {
123+ const result = lastOperand / parseInt ( inputWindow . value ) ;
124+ operation = null ;
125+ lastOperand = 0 ;
126+ inputWindow . value = result ;
127+ }
128+ } ) ;
129+
130+ // Извлечение квадратного корня
131+ document . getElementById ( 'btn_calc' ) . addEventListener ( 'click' , function ( ) {
132+ if ( operation === 'sqrt' ) {
133+ const result = lastOperand ;
134+ operation = null ;
135+ lastOperand = 0 ;
136+ inputWindow . value = Math . sqrt ( result ) ;
137+ }
138+ } ) ;
139+
140+ // СБРОС из окна ввода
7141document . getElementById ( 'btn_clr' ) . addEventListener ( 'click' , function ( ) {
8142 lastOperand = 0 ;
9143 operation = null ;
10144 inputWindow . value = '' ;
11- } )
145+ } ) ;
12146
0 commit comments