Ask Your Question
1

How can I allow the player to define the range for the number guessing game?

asked 2023-06-06 07:18:54 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2023-06-06 07:34:01 +0000

bukephalos gravatar image
  1. Create a prompt that asks the player to enter the minimum and maximum numbers for the range of the game.

  2. Store the minimum and maximum values entered by the player in separate variables.

  3. Generate a random number within the range that the player defined using the Math.random() function.

  4. Ask the player to guess a number within the range they specified.

  5. Check if the player’s guess is higher or lower than the generated number and provide feedback accordingly.

  6. Repeat steps 4 and 5 until the player guesses the correct number.

  7. You may also need to add input validation to ensure that the values entered by the player are valid numbers and that the minimum value is less than the maximum value.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-06 07:18:54 +0000

Seen: 19 times

Last updated: Jun 06 '23