-
Notifications
You must be signed in to change notification settings - Fork 15k
Description
Checks
- This is not a duplicate of an existing issue (please have a look through our open issues list to make sure)
- I have thoroughly read and understand The Odin Project Contributing Guide
- Would you like to work on this issue?
Describe your suggestion
In the Pure Functions lesson, the guessingGame example is used to demonstrate separating logic from side effects. The current version uses prompt once to get the user’s guess, but it does not handle the case where the user enters a number outside the valid range (1–100) or cancels/enters nothing.
It might be helpful for learners if the lesson showed a simple while loop to re-prompt the user until they enter a valid number between 1 and 100.
This way, the evaluateGuess function stays pure and focused on the comparison logic, while input validation happens in the main game loop — keeping responsibilities clear and testable.
function guessingGame() {
const magicNumber = 22;
let guess;
do {
guess = Number(prompt('Guess a number between 1 and 100!'));
} while (isNaN(guess) || guess < 1 || guess > 100);
const message = evaluateGuess(magicNumber, guess);
alert(message);
}
Path
Node / JS
Lesson Url
https://www.theodinproject.com/lessons/node-path-javascript-more-testing
(Optional) Discord Name
No response
(Optional) Additional Comments
No response