Spaces:
Running
Running
Show Unique Images to user
#2
by
dhanushreddy29
- opened
- index.html +6 -1
index.html
CHANGED
@@ -142,8 +142,13 @@
|
|
142 |
highscoreElement.textContent = highscore;
|
143 |
|
144 |
function preloadImages(count = 20) {
|
|
|
145 |
for (let i = 1; i <= count; i++) {
|
146 |
-
|
|
|
|
|
|
|
|
|
147 |
const paddedIndex = index.toString().padStart(2, '0');
|
148 |
|
149 |
const realImg = new Image();
|
|
|
142 |
highscoreElement.textContent = highscore;
|
143 |
|
144 |
function preloadImages(count = 20) {
|
145 |
+
const uniqueIndexes = new Set();
|
146 |
for (let i = 1; i <= count; i++) {
|
147 |
+
let index = Math.floor(Math.random() * totalImages) + 1;
|
148 |
+
while (uniqueIndexes.has(index)) {
|
149 |
+
index = Math.floor(Math.random() * totalImages) + 1;
|
150 |
+
}
|
151 |
+
uniqueIndexes.add(index);
|
152 |
const paddedIndex = index.toString().padStart(2, '0');
|
153 |
|
154 |
const realImg = new Image();
|