-
Notifications
You must be signed in to change notification settings - Fork 0
/
highscore.js
25 lines (22 loc) · 910 Bytes
/
highscore.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
const stats = {
dailyStreak: localStorage.getItem("daily-streak"),
};
const setScoreInRecords = (mode, currentScore) => {
const previousHighScore =
Number(localStorage.getItem(`${mode}-highscore`)) || 0;
const highscore = Math.max(currentScore, previousHighScore);
localStorage.setItem(`${mode}-highscore`, highscore);
document.querySelector(".highscore").innerText = highscore;
};
const getStreak = () => Number(localStorage.getItem("daily-streak")) || 0;
const addToStreak = (daySeed) => {
const streak = getStreak();
if (Number(localStorage.getItem("users-previous-seed")) + 1 === daySeed) {
localStorage.setItem("users-previous-seed", daySeed);
localStorage.setItem("daily-streak", streak + 1);
} else {
localStorage.setItem("users-previous-seed", daySeed);
localStorage.setItem("daily-streak", 1);
}
document.querySelector(".streak").innerText = getStreak();
};