ItsJayKee commited on
Commit
628b3ee
·
verified ·
1 Parent(s): bb5b9f7

okay don't show the result yet until the code is finished, and when it is finieshed show how much time was taken

Browse files
Files changed (1) hide show
  1. script.js +11 -9
script.js CHANGED
@@ -324,15 +324,13 @@ function updateDisplay() {
324
  correctChars++;
325
  }
326
  }
327
-
328
  // End game if all characters are typed correctly
329
  if (inputText.length === codeSpans.length && allCorrect) {
330
- endGame();
331
  }
332
  }
333
-
334
  // End the game
335
- function endGame() {
336
  clearInterval(timer);
337
  isPlaying = false;
338
  inputField.disabled = true;
@@ -343,12 +341,16 @@ function endGame() {
343
  const wordsTyped = correctChars / 5;
344
  const wpm = Math.round((wordsTyped / timeTaken) * 60);
345
  const accuracy = Math.round((correctChars / totalChars) * 100);
346
- // Display results
347
- finalWPM.textContent = wpm;
348
- finalAccuracy.textContent = `${accuracy}%`;
349
- resultsSection.classList.remove('hidden');
 
 
 
 
 
350
  }
351
-
352
  // Event listeners
353
  inputField.addEventListener('input', updateDisplay);
354
  inputField.addEventListener('focus', startGame);
 
324
  correctChars++;
325
  }
326
  }
 
327
  // End game if all characters are typed correctly
328
  if (inputText.length === codeSpans.length && allCorrect) {
329
+ endGame(true);
330
  }
331
  }
 
332
  // End the game
333
+ function endGame(isCompleted = false) {
334
  clearInterval(timer);
335
  isPlaying = false;
336
  inputField.disabled = true;
 
341
  const wordsTyped = correctChars / 5;
342
  const wpm = Math.round((wordsTyped / timeTaken) * 60);
343
  const accuracy = Math.round((correctChars / totalChars) * 100);
344
+
345
+ // Only show results if code was completed or time ran out
346
+ if (isCompleted || timeLeft <= 0) {
347
+ // Display results
348
+ finalWPM.textContent = wpm;
349
+ finalAccuracy.textContent = `${accuracy}%`;
350
+ finalTime.textContent = `${timeTaken}s`;
351
+ resultsSection.classList.remove('hidden');
352
+ }
353
  }
 
354
  // Event listeners
355
  inputField.addEventListener('input', updateDisplay);
356
  inputField.addEventListener('focus', startGame);