-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (26 loc) · 958 Bytes
/
app.js
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
let squares = document.querySelectorAll('.square');
let result = document.getElementById('result');
let sq_array = Array.prototype.slice.call(squares);
let timer = setInterval(colorSquares, 1000);
let counter = 0;
function colorSquares() {
let sq = sq_array[randomP()];
if(counter < 100) {
if(sq.hasAttribute('filled') === false) {
sq.style.backgroundColor = `rgba(${getRandom()},${getRandom()},${getRandom()},.6)`;
sq.setAttribute('filled', true);
counter++;
} else {
colorSquares();
};
} else {
clearInterval(timer);
result.textContent = 'Заполнение завершено';
};
};
function randomP(min = 0, max = 99){
return Math.floor(Math.random() * (max - min + 1) + min);
};
function getRandom(min = 0, max = 255){
return Math.floor(Math.random() * (max - min) + min + 1);
};