-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·215 lines (181 loc) · 4.97 KB
/
index.html
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html>
<html>
<style>
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body, html {
font-size: 1.3rem;
line-height: 1.5em;
font-family: "Roboto",Helvetica,Arial,sans-serif;
padding: 0;
margin: 0;
}
#ball {
width: 100%;
display: flex;
border-radius: 100%;
position: relative;
align-items: center;
justify-content: center;
max-width: 150px!important;
margin: 0 auto;
box-shadow: inset 0.5rem 0.5rem 1.5rem 0.25rem hsla(0,0%,100%,.3), inset -0.25rem -0.25rem 1.5rem 0.5rem rgba(0,0,0,.4);
}
.red {
background: radial-gradient(circle at 20% 20%,red,#910000);
}
.yellow {
background: radial-gradient(circle at 20% 20%,#ffe52a,#f7bd00);
}
.yellow .content {
border: .15rem solid #f7bd00;
}
.red .content {
border: .15rem solid red;
}
.blue .content {
border: .15rem solid #00f;
}
.blue {
background: radial-gradient(circle at 20% 20%,#00f,#0000ad);
}
.content {
text-align: center;
border-radius: 100%;
background: #fff;
position: relative;
min-width: 1rem;
padding: 25%;
box-shadow: inset -0.5rem -0.5rem 2rem 0 rgba(0,0,0,.16), 0 0 0 0.25rem #fff;
background: radial-gradient(circle at 20% 20%,#fff,#efefef);
}
.green {
background: radial-gradient(circle at 20% 20%,green,#004a00);
}
.green .content {
border: .15rem solid green;
}
.white {
background: radial-gradient(circle at 20% 20%,#fff,#b6b6b6);
}
.white .content {
border: .15rem solid red;
}
.padding {
padding: 1rem;
}
.content span {
justify-content: center;
align-items: center;
position: absolute;
text-align: center;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: inline-flex;
font-weight: 700;
font-size: 1rem;
line-height: 1;
}
</style>
<body onload="initializePage()">
<h2>Alivia's Bingo</h2>
<input type="text" id="txtbox">
<button onclick="addBingoBall()">Add</button>
<button onclick="undoBingoBall()">Undo</button>
<button onclick="clearBingoBalls()">Clear</button>
<script>
var ballCounter = 0;
function initializePage() {
document.getElementById('txtbox').focus();
}
function clearBingoBalls() {
var table = document.getElementById('bingoTable');
table.deleteRow(0);
table.insertRow(0);
clearTextBox();
ballCounter = 0;
}
function clearTextBox() {
document.getElementById('txtbox').value = "";
document.getElementById('txtbox').focus();
}
function deleteCell(cellToDelete) {
console.log("Deleting cell number " + cellToDelete);
var row = document.getElementById('bingoTable').rows[0];
row.deleteCell(cellToDelete);
}
function insertCell(cellToInsert, textToInsert, colour) {
console.log("Inserting cell with " + textToInsert + " into position " + cellToInsert);
var row = document.getElementById('bingoTable').rows[0];
var x = row.insertCell(cellToInsert);
x.innerHTML = "<div class='padding'><div id='ball' class='" + colour + " relative notranslate' style='height: 150px; width: 150px;'><div class='content'><span>" + textToInsert + "</span></div></div></div>";
clearTextBox();
}
function addBingoBall() {
var bingoNumber = document.getElementById('txtbox').value;
if(bingoNumber) {
console.log("bingoNumber to be added " + bingoNumber);
} else {
console.log("No value has been entered, exiting.");
return;
}
if (bingoNumber >= 1 && bingoNumber <= 90) {
console.log("Number falls within the allowed range");
} else {
console.log("Number is outside allowed range, exiting.");
return;
}
console.log("Ball Count: " + ballCounter);
ballCounter = ballCounter + 1;
var row = document.getElementById('bingoTable').rows[0];
cellCount = row.cells.length;
console.log("Cell Count: " + cellCount);
var colour;
switch (ballCounter) {
case 1:
colour = "red";
break;
case 2:
colour = "yellow";
break;
case 3:
colour = "blue";
break;
case 4:
colour = "green";
break;
case 5:
colour = "white";
break;
}
console.log("Found " + cellCount + " cells.");
if(cellCount === 5) {
deleteCell(0);
insertCell(4, bingoNumber, colour)
} else {
insertCell(cellCount, bingoNumber, colour);
}
if (ballCounter === 5) {
ballCounter = 0;
}
}
function undoBingoBall() {
var row = document.getElementById('bingoTable').rows[0];
cellCount = row.cells.length;
deleteCell(cellCount - 1);
clearTextBox();
if (ballCounter !== 0) {
ballCounter -= 1;
}
}
</script>
<table id="bingoTable">
<tr>
</tr>
</table>
</body>
</html>