Full typescript and mvvm implementation #3

Merged
Schmidii99 merged 26 commits from Developer into main 2023-04-23 20:02:32 +02:00
Showing only changes of commit 1fb4e3f8e3 - Show all commits

23
js/statistics.js Normal file
View File

@ -0,0 +1,23 @@
class Stats {
#score;
#highScore;
#highScoreStorageKey;
constructor(highScoreStorageKey) {
// used as key for localStorage
this.#highScoreStorageKey = highScoreStorageKey;
this.#score = 0;
this.#highScore = localStorage.getItem(this.#highScoreStorageKey) ?? 0;
}
incrementScore(value = 1) {
this.#score += value;
if (this.#highScore < this.#score) {
this.#highScore = this.#score;
localStorage.setItem(this.#highScoreStorageKey, this.#highScore);
}
}
}