-
Notifications
You must be signed in to change notification settings - Fork 0
/
highscores.js
31 lines (31 loc) · 1015 Bytes
/
highscores.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
async function submitHighScore(event) {
event.preventDefault();
const inputName = document.getElementById("input_name").value;
if (inputName) {
const result = await db.collection("highscores").doc().set({
name: inputName,
time: secondsSinceStart,
timestamp: new Date(),
});
document.getElementById("high-score-submit").style.display = "none";
document.getElementById("submit-confirm").style.display = "";
}
}
async function getHighScores() {
const results = await db
.collection("highscores")
.orderBy("time", "desc")
.limit(20)
.get();
const orderedHighScores = await results.docs.map((doc) => doc.data());
console.log(orderedHighScores);
orderedHighScores.forEach((score) => {
let listItem = document.createElement("LI");
listItem.innerText = score.name + " - " + score.time + "s";
document.getElementById("leaderboard-list").appendChild(listItem);
});
}
function reloadPage(event) {
event.preventDefault();
location.reload();
}