Skip to content

Fix bugs in guessing game and maintain reset functionality#267

Open
shanny2022 wants to merge 4 commits into
Code-the-Dream-School:mainfrom
shanny2022:main
Open

Fix bugs in guessing game and maintain reset functionality#267
shanny2022 wants to merge 4 commits into
Code-the-Dream-School:mainfrom
shanny2022:main

Conversation

@shanny2022
Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings March 9, 2026 07:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the guessing game’s core gameplay flow by correcting message handling, input validation, and wiring guesses through a form submission while preserving reset-driven replay.

Changes:

  • Added a <form> wrapper so guesses can be submitted via Enter key and handled via submit event.
  • Refactored game logic to reset state in setup(), hide/show messages consistently, and fix end-of-game behavior.
  • Added input validation and improved guess feedback text (including pluralization).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
index.js Introduces form submit handling, input validation, improved message toggling, and a consolidated setup() reset flow.
index.html Wraps guess input/button in a form and adds instructional comments to match the updated interaction model.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread index.js
Comment on lines +56 to +62
const guess = parseInt(guessInput.value, 10);

if (!Number.isInteger(guess) || guess < 1 || guess > 99) {
hideAllMessages();
numberOfGuessesMessage.style.display = '';
numberOfGuessesMessage.innerHTML = `You guessed ${guess}. <br> ${remainingAttempts} guesses remaining`;
numberOfGuessesMessage.innerHTML = 'Enter a number from 1 to 99.';
resetButton.style.display = attempts > 0 ? '' : 'none';
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseInt() will truncate decimals (e.g., 1.9 becomes 1) and can accept partially numeric strings, so some invalid inputs may be treated as valid guesses. Consider using Number(guessInput.value) and validating with Number.isInteger() (and range) so non-integers are rejected rather than coerced.

Copilot uses AI. Check for mistakes.
Comment thread index.js
Comment on lines 90 to 92
guessInput.value = '';

resetButton.style.display = '';
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetButton.style.display = '' is set after every valid guess, but setup() hides the reset button and the UI copy suggests reset is only intended after win/max guesses. Either only show reset when the game is over (win/lose), or update the behavior/copy to match the intended UX.

Copilot uses AI. Check for mistakes.
Comment thread index.html
Would you like to play again?
</p>
</div>
<!-- Reset starts a brand-new game after a win or after using all guesses. -->
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says reset starts a new game "after a win or after using all guesses", but the current JS shows the reset button after any valid guess. Update this comment or adjust the reset-button visibility logic so the code and instructions stay consistent.

Suggested change
<!-- Reset starts a brand-new game after a win or after using all guesses. -->
<!-- Reset lets the player start a brand-new game at any time. -->

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants