diff --git a/js/statistics.js b/js/statistics.js new file mode 100644 index 0000000..d7aa863 --- /dev/null +++ b/js/statistics.js @@ -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); + } + } +} \ No newline at end of file