-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (66 loc) · 2.36 KB
/
script.js
File metadata and controls
78 lines (66 loc) · 2.36 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const boxes = [
document.querySelector('.box-1'),
document.querySelector('.box-2'),
document.querySelector('.box-3'),
document.querySelector('.box-4')
];
const letters = ['P', 'L', 'A', 'Y'];
let correctOrder = ['P', 'L', 'A', 'Y'];
let currentAttempt = [];
let shuffledLetters = [];
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function assignRandomLetters() {
shuffledLetters = shuffleArray([...letters]);
boxes.forEach((box, index) => {
box.textContent = shuffledLetters[index];
box.style.color = 'white';
box.style.fontSize = '128px';
box.style.display = 'flex';
box.style.justifyContent = 'center';
box.style.alignItems = 'center';
box.style.cursor = 'crosshair';
box.style.visibility = 'visible';
});
currentAttempt = [];
}
function handleLetterClick(event) {
const clickedLetter = event.target.textContent;
currentAttempt.push(clickedLetter);
const currentIndex = currentAttempt.length - 1;
if (clickedLetter !== correctOrder[currentIndex]) {
const container = document.querySelector('.container')
container.style.borderColor = "#FF3C38"
setTimeout(() => {
container.style.borderColor = "transparent"
assignRandomLetters();
}, 550);
} else {
event.target.innerHTML = '';
if (currentAttempt.length === correctOrder.length) {
const container = document.querySelector('.container')
container.style.borderColor = "#53FF45"
setTimeout(() => {
container.style.borderColor = "transparent"
assignRandomLetters();
}, 550);
}
}
}
boxes.forEach(box => {
box.addEventListener('click', handleLetterClick);
});
assignRandomLetters();
const board = document.getElementById('board');
const distanceSlider = document.getElementById('distanceSlider');
function adjustBoardScale() {
const scaleValue = 1 + (distanceSlider.value / 100);
board.style.transform = `scale(${scaleValue})`;
}
distanceSlider.addEventListener('input', adjustBoardScale);
adjustBoardScale();