Question: In this lab you'll develop a simple guessing game that involves trying to pick an integer between 1 and 100, randomly chosen by the computer.
In this lab you'll develop a simple guessing game that involves trying to pick an integer between 1 and 100, randomly chosen by the computer. To help keep things manageable, we'll add features incrementally. Be sure to thoroughly test your program at each step! 1. Let's start with the basics! Write a program that makes the computer pick a random integer between 1-100 (inclusive), then uses a loop to repeatedly get user input until s/he enters the correct number. Remember that you can generate a random integer using the Math.random() method - see the solution for Problem 5 of our conditionals problem set for an example of this. 2. Make your program indicate whether the player's guesses are too high or too low. Also add some error checking to ensure that s/he cannot enter guesses below 1 or above 100. Make your program track the number of guesses made by the player. Show this number once s/he gets it right. Invalid guesses (those below 1 or above 100) should NOT count towards this number. 3. Below is an example of what your final program might look like when you run it (the underlined parts indicate what you type in as the program is running): I'm thinking of an integer between 1 and 100. Try to guess what it is! Enter your guess: 50 That's too low! Enter your guess: 101 You must enter a number between 1-100. Enter your guess: 100 That's too high! Enter your guess: 75 That's too high! Enter your guess: 60 That's too high! Enter your guess: 55 That's too high! Enter your guess: 52 That's too high! Enter your guess: 51 You got it! It took you 7 tries to get the right number
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
