Solution Review
Explore how to create a number guessing game by generating a random secret number and using conditional statements to check users’ guesses. Understand how infinite and fixed iteration loops control gameplay. Learn to implement win checks, provide hints, and limit attempts, gaining hands-on Java coding experience within this project.
We'll cover the following...
We'll cover the following...
Task I: Generate the secret number
The task was to generate a random number to be guessed by the player.
We can use the formula Math.random() * (max - min + 1) to generate a random value between 0 and 100 (inclusive). Our max value is 100 and our min is 0.
Task II: Implement the game logic
The task was to check for a win, and if the player doesn’t meet the win condition, give them hints about how near or far their number is from the secret number.
-
Line 4: The
while(true)...