From 36c759cfe69e5e4966b91a590f85bcc6b3776fd7 Mon Sep 17 00:00:00 2001 From: Florian Schmid Date: Fri, 21 Apr 2023 22:54:38 +0200 Subject: [PATCH] implement explicit types --- src/statistics.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/statistics.ts b/src/statistics.ts index b28ed5a..f320c64 100644 --- a/src/statistics.ts +++ b/src/statistics.ts @@ -1,15 +1,14 @@ export class Stats { - #score; - #highScore; - #highScoreStorageKey; + #score: number; + #highScore: number; + #highScoreStorageKey: string; constructor(highScoreStorageKey) { // used as key for localStorage - this.#highScoreStorageKey = highScoreStorageKey; this.#score = 0; - this.#highScore = localStorage.getItem(this.#highScoreStorageKey) ?? 0; + this.#highScore = Number(localStorage.getItem(this.#highScoreStorageKey)) ?? 0; } incrementScore(value = 1) { @@ -17,19 +16,19 @@ export class Stats { if (this.#highScore < this.#score) { this.#highScore = this.#score; - localStorage.setItem(this.#highScoreStorageKey, this.#highScore); + localStorage.setItem(this.#highScoreStorageKey, this.#highScore.toString()); } } - resetScore() { + resetScore(): void { this.#score = 0; } - get highScore() { + get highScore(): number { return this.#highScore; } - get score() { + get score(): number { return this.#score; } } \ No newline at end of file