-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
177 lines (161 loc) · 4.26 KB
/
main.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
const output = document.getElementById("output"),
numbersRemaining = document.getElementById("numbersRemaining"),
rollButton = document.getElementById("rollButton"),
newGameButton = document.getElementById("newGame"),
recentNumbersOutput = document.getElementById("recentNumbers"),
callout = document.getElementById("callout");
let bingoNumbers = [],
recentNumbers = [],
randomIndex = 0,
modalShown = false;
const callouts = {
1: "Kelly’s eye",
46: "Up to tricks",
2: "One little duck",
47: "Four and seven",
3: "Cup of tea",
48: "Four dozen",
4: "Knock at the door",
49: "PC",
5: "Man alive",
50: "Half a century",
6: "Half a dozen",
51: "Tweak of the thumb",
7: "Lucky seven",
52: "Danny La Rue",
8: "Garden gate",
53: "Stuck in a tree",
9: "Doctor’s orders",
54: "Clean the floor",
10: "Borris’s den",
55: "Snakes alive",
11: "Legs eleven",
56: "Was she worth it?",
12: "One dozen",
57: "Heinz varieties",
13: "Unlucky for some",
58: "Make them wait",
14: "Valentine’s Day",
59: "Brighton Line",
15: "Young and keen",
60: "Five dozen",
16: "Sweet 16",
61: "Baker’s bun",
17: "Dancing queen",
62: "Tickety-boo",
18: "Coming of age",
63: "Tickle me",
19: "Goodbye teens",
64: "Red raw",
20: "One score",
65: "Old age pension",
21: "Royal salute",
66: "Clickety click",
22: "Two little ducks",
67: "Stairway to heaven",
23: "Thee and me",
68: "Saving Grace",
24: "Two dozen",
69: "Favourite of mine",
25: "Duck and dive",
70: "Three score and ten",
26: "Pick and mix",
71: "Bang on the drum",
27: "Gateway to heaven",
72: "Six dozen",
28: "Over weight",
73: "Queen bee",
29: "Rise and shine",
74: "Hit the floor",
30: "Dirty Gertie",
75: "Strive and strive",
31: "Get up and run",
76: "Trombones",
32: "Buckle my shoe",
77: "Sunset strip",
33: "Fish, chips & peas",
78: "39 more steps",
34: "Ask for more",
79: "One more time",
35: "Jump and jive",
80: "Eight and blank",
36: "Three dozen",
81: "Stop and run",
37: "More than eleven",
82: "Straight on through",
38: "Christmas cake",
83: "Time for tea",
39: "39 steps",
84: "Seven dozen",
40: "Life begins",
85: "Staying alive",
41: "Time for fun",
86: "Between the sticks",
42: "Winnie the Pooh",
87: "Torquay in Devon",
43: "Down on your knees",
88: "Two fat ladies",
44: "Droopy drawers",
89: "Nearly there",
45: "Halfway there",
90: "Top of the shop",
};
const newGame = () => {
rollButton.style.visibility = "visible";
newGameButton.style.backgroundColor = "rgb(238, 107, 107)";
generateNewBingoArrays();
rollNewNumber();
};
const generateNewBingoArrays = () => {
bingoNumbers = [];
recentNumbers = ["", "", "", "", ""];
for (let i = 1; i <= 90; i++) {
bingoNumbers.push(i);
}
};
const setRandomIndex = () =>
(randomIndex = Math.floor(Math.random() * bingoNumbers.length));
const rollNewNumber = () => {
setRandomIndex();
output.classList.add("slide-out-right");
setTimeout(() => {
output.classList.remove("slide-out-right");
output.innerHTML = bingoNumbers[randomIndex];
callout.innerHTML = callouts[bingoNumbers[randomIndex]];
output.classList.add("slide-in-left");
numbersRemaining.innerHTML = bingoNumbers.length - 1;
recentNumbers.pop();
recentNumbers.unshift(bingoNumbers[randomIndex]);
recentNumbersOutput.innerHTML = recentNumbers
.map((number, index) => {
return `<span ${
index == 0 ? `class="slide-in-top"` : null
}>${number}</span>`;
})
.join("");
bingoNumbers.splice(randomIndex, 1);
checkLose() ? styleLose() : null;
newGameButton.disabled = false;
rollButton.disabled = false;
}, 500);
newGameButton.disabled = true;
rollButton.disabled = true;
};
const checkLose = () => bingoNumbers.length == 0;
const styleLose = () => {
newGameButton.style.backgroundColor = "lightgreen";
rollButton.style.visibility = "hidden";
};
const toggleModal = (shown) => {
const modal = document.getElementById("modal");
modalShown = shown;
if (modalShown) {
modal.style.display = "flex";
} else {
modal.style.display = "none";
}
};
document.getElementById("modalYes").addEventListener("click", () => {
toggleModal(false);
newGame();
});