Spaces:
Running
Running
feat: Implement "You've outperformed X% of players" feature
Browse files- index.html +9 -1
index.html
CHANGED
@@ -98,7 +98,7 @@
|
|
98 |
<p id="game-over-message" class="text-lg text-gray-500">
|
99 |
You found 0 fake insects in 25 seconds.
|
100 |
</p>
|
101 |
-
<p class="text-md text-gray-500">You've outperformed
|
102 |
</div>
|
103 |
|
104 |
<button
|
@@ -207,6 +207,12 @@
|
|
207 |
scoreElement.textContent = score;
|
208 |
}
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
function endGame(reason) {
|
211 |
clearInterval(timer);
|
212 |
document.getElementById('countdown-sound').pause();
|
@@ -220,6 +226,8 @@
|
|
220 |
} else {
|
221 |
gameOverReasonElement.textContent = "You clicked a real insect!";
|
222 |
}
|
|
|
|
|
223 |
gameOverOverlay.classList.remove('hidden');
|
224 |
}
|
225 |
|
|
|
98 |
<p id="game-over-message" class="text-lg text-gray-500">
|
99 |
You found 0 fake insects in 25 seconds.
|
100 |
</p>
|
101 |
+
<p id="performance-percentage" class="text-md text-gray-500">You've outperformed 0% of players.</p>
|
102 |
</div>
|
103 |
|
104 |
<button
|
|
|
207 |
scoreElement.textContent = score;
|
208 |
}
|
209 |
|
210 |
+
function calculatePerformancePercentage(score) {
|
211 |
+
const topScore = 35;
|
212 |
+
const percentage = Math.min(100, Math.max(0, (score / topScore) * 100));
|
213 |
+
return Math.round(percentage);
|
214 |
+
}
|
215 |
+
|
216 |
function endGame(reason) {
|
217 |
clearInterval(timer);
|
218 |
document.getElementById('countdown-sound').pause();
|
|
|
226 |
} else {
|
227 |
gameOverReasonElement.textContent = "You clicked a real insect!";
|
228 |
}
|
229 |
+
const performancePercentage = calculatePerformancePercentage(score);
|
230 |
+
document.getElementById('performance-percentage').textContent = `You've outperformed ${performancePercentage}% of players.`;
|
231 |
gameOverOverlay.classList.remove('hidden');
|
232 |
}
|
233 |
|