Skip to content

Commit 282342a

Browse files
committed
Загрузка проекта SkillfactoryCoding#1
1 parent 00c4b55 commit 282342a

File tree

3 files changed

+220
-1
lines changed

3 files changed

+220
-1
lines changed

bjs/07_Number_and_string/index.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,66 @@
2121
<button class="btn btn-outline-danger form-control" id="btn_clr">C</button>
2222
</div>
2323
</div>
24+
<div class="row no-gutters">
25+
<div class="col">
26+
<button class="btn btn-outline-primary form-control" id="btn_1">1</button>
27+
</div>
28+
<div class="col">
29+
<button class="btn btn-outline-primary form-control" id="btn_2">2</button>
30+
</div>
31+
<div class="col">
32+
<button class="btn btn-outline-primary form-control" id="btn_3">3</button>
33+
</div>
34+
<div class="col">
35+
<button class="btn btn-outline-primary form-control" id="btn_sum">+</button>
36+
</div>
37+
</div>
38+
<div class="row no-gutters">
39+
<div class="col">
40+
<button class="btn btn-outline-primary form-control" id="btn_4">4</button>
41+
</div>
42+
<div class="col">
43+
<button class="btn btn-outline-primary form-control" id="btn_5">5</button>
44+
</div>
45+
<div class="col">
46+
<button class="btn btn-outline-primary form-control" id="btn_6">6</button>
47+
</div>
48+
<div class="col">
49+
<button class="btn btn-outline-primary form-control" id="btn_diff">-</button>
50+
</div>
51+
</div>
52+
<div class="row no-gutters">
53+
<div class="col">
54+
<button class="btn btn-outline-primary form-control" id="btn_7">7</button>
55+
</div>
56+
<div class="col">
57+
<button class="btn btn-outline-primary form-control" id="btn_8">8</button>
58+
</div>
59+
<div class="col">
60+
<button class="btn btn-outline-primary form-control" id="btn_9">9</button>
61+
</div>
62+
<div class="col">
63+
<button class="btn btn-outline-primary form-control" id="btn_mult">*</button>
64+
</div>
65+
66+
</div>
67+
<div class="row no-gutters">
68+
<div class="col">
69+
<button class="btn btn-outline-primary form-control" id="btn_calc">=</button>
70+
</div>
71+
<div class="col">
72+
<button class="btn btn-outline-primary form-control" id="btn_0">0</button>
73+
</div>
74+
<div class="col">
75+
<button class="btn btn-outline-primary form-control" id="btn_sqrt">&#8730</button>
76+
</div>
77+
<div class="col">
78+
<button class="btn btn-outline-primary form-control" id="btn_sep">&#247</button>
79+
</div>
80+
81+
82+
</div>
83+
</div>
2484
</div>
2585
</div>
2686
</div>

bjs/07_Number_and_string/script.js

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,144 @@ let operation = null;
33

44
const 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+
// СБРОС из окна ввода
7141
document.getElementById('btn_clr').addEventListener('click', function () {
8142
lastOperand = 0;
9143
operation = null;
10144
inputWindow.value = '';
11-
})
145+
});
12146

bjs/07_Number_and_string/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,28 @@
77
text-align: end;
88
font-size: x-large;
99
}
10+
11+
body {
12+
background-color: rgb(255, 255, 255);
13+
}
14+
15+
#calc {
16+
color: white;
17+
background-color: rgb(0, 0, 0);
18+
}
19+
20+
#btn_1, #btn_2, #btn_3, #btn_4, #btn_5, #btn_6, #btn_7,
21+
#btn_8, #btn_9, #btn_0, #btn_sum, #btn_diff, #btn_mult,
22+
#btn_sqrt, #btn_sep {
23+
color: white;
24+
background-color: blue;
25+
}
26+
27+
#btn_calc {
28+
color: white;
29+
background-color: green;
30+
}
31+
32+
#btn_clr {
33+
background-color: rgb(255, 0, 0);
34+
}

0 commit comments

Comments
 (0)