fixed error when there are no words in history

closes #2879
This commit is contained in:
Miodec 2022-04-27 16:04:34 +02:00
parent 34659f471d
commit 4f8c5bb941

View file

@ -279,11 +279,12 @@ export function setLastSecondNotRound(): void {
export function calculateBurst(): number {
const timeToWrite = (performance.now() - TestInput.currentBurstStart) / 1000;
let wordLength;
let wordLength: number;
wordLength = TestInput.input.current.length;
if (wordLength == 0) {
wordLength = TestInput.input.getHistoryLast().length;
wordLength = TestInput.input.getHistoryLast()?.length ?? 0;
}
if (wordLength == 0) return 0;
const speed = Misc.roundTo2((wordLength * (60 / timeToWrite)) / 5);
return Math.round(speed);
}