Skip to content

Commit 38f89d9

Browse files
authored
Update snake.js
1 parent 5702346 commit 38f89d9

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎src/js/snake.js‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,19 @@ SNAKE.Snake =
244244
blockPool[blockPool.length] = tempBlock;
245245
}
246246

247-
function recordScore() {
248-
const highScore = localStorage[HIGH_SCORE_KEY];
249-
if (me.snakeLength > highScore) {
250-
alert(
251-
"Congratulations! You have beaten your previous high score, which was " +
252-
highScore +
253-
".",
254-
);
255-
localStorage.setItem(HIGH_SCORE_KEY, me.snakeLength);
247+
function recordScore() {
248+
const highScore = localStorage[HIGH_SCORE_KEY] || 0; // Ensure highScore is defined
249+
if (me.snakeLength > highScore) {
250+
// Update the UI instead of using alert
251+
const messageBox = document.getElementById("score-message");
252+
if (messageBox) {
253+
messageBox.textContent = `Congratulations! You have beaten your previous high score, which was ${highScore}.`;
254+
messageBox.style.display = "block"; // Make sure the message is visible
256255
}
257-
}
256+
localStorage.setItem(HIGH_SCORE_KEY, me.snakeLength);
257+
}
258+
}
259+
258260

259261
function handleEndCondition(handleFunc) {
260262
recordScore();

0 commit comments

Comments
 (0)