Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Please make the following modifications to the code: 1. Prompt for Max Number Instead of locking the game into a number between1and20, use theprompt()method to ask the user what the maximum number...

1 answer below »
Please make the following modifications to the code:

1. Prompt for Max Number


Instead of locking the game into a number between1and20, use theprompt()method to ask the user what the maximum number should be. The prompt should be in a loop with validation, as demonstrated previously in the course, making sure that the inputted value is a positive number. If the user inputs a decimal, simply round it.


When a valid number is inputted, change the content of the instructions to specify guesses between1andN(whereNis the user-provided maximum number).


Grading Criteria



  • The application prompts the user for a maximum number.

  • The application validates the user input and does not allow invalid entries (negative numbers,0, or non-numbers), re-prompting the user if an invalid entry is provided.

  • If the user provides a decimal number, the application rounds it.

  • The application selects a random number between1andN(whereNis the user-provided maximum number).


2. Validate the Guess


When the user presses the guess button, validate the input:



  • If the guess is not a number, display a message: "That is not a number!"

  • If the guess is out of range (1toN), display a message: "That number is not in range, try again."


Grading Criteria



  • The application prevents the user from guessing a non-number and displays an appropriate error message.

  • The application prevents the user from guessing a number less than1and displays an appropriate error message.

  • The application prevents the user from guessing a number greater thanNand displays an appropriate error message.


3. Track the Guesses


Using an array, keep track of each guess by the user. When the user wins the game by guessing correctly, add the number of guesses and the list of guesses to the victory message. For example:


"You got it! It took you 5 tries and your guesses were 3, 14, 7, 9, 5."


Do not count invalid guesses (not numbers or out of range).


Grading Criteria



  • The application correctly initializes an array and uses thepush()function to add the guesses.

  • The application correctly formats the win message to include the comma-delimited guesses as part of the output.

  • The application uses thelengthproperty and does not use an extra variable to count the number of guesses.


4. Prevent Duplicate Guesses


Since you are tracking the guesses, add validation to check if a number has already been guessed. If it has, display a message and do not count it as a guess.


Grading Criteria



  • The application correctly checks the array for a guess first using any means (loop,find(), etc.) before adding a guess to the array.

  • The application correctly displays a message that a number has already been guessed.


Answered Same Day Feb 16, 2023

Solution

Aditi answered on Feb 17 2023
33 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here