Question

A Backwards Guessing Game For this assignment, you will be a making a guessing game with...

A Backwards Guessing Game For this assignment, you will be a making a guessing game with a twist. You will play the role of the computer, and the computer will try to guess the number. You will think of a number (you don’t have to read it in as input) between 1 and 100. You will create a loop that runs 5 times. In this loop, the computer will try to guess the number in the range it knows is valid (to start, the range will be 1-100) and will print out the guess on the screen. Next, it will ask you if you its guess is correct. You will respond with “High”, “Low”, or “Correct”. If it is not correct, the computer will adjust its range and loop around to guess again. If it is correct, the computer will print out a happy message and exit. If the computer has not guessed correctly after 5 tries, it will print out a sad message and exit. Sample Output (User-Typed Information Is Bolded/Underlined): Time to play Guessing Game! I think the number is 27. How’d I do? Low I think the number is 92. How’d I do? High I think the number is 58. How’d I do? Correct Yes! I won!

Write a program in the language of your choice to implement the backwards guessing games. I would like to see it written in Javascript.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!DOCTYPE html>
<html>
<body>


<script>

function getAGuess(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

low = 1
high = 100
guess = getAGuess(low, high)
numGuesses = 0

do {
        x = prompt('I think the number is ' + guess + '. How\'d I do?')
        if(x == 'Correct') {
                alert('Yes! I won!')
                break
        }
        numGuesses += 1
        if(x == 'Low') {
                low = guess + 1
        } else {
                high = guess - 1
        }
        guess = getAGuess(low, high)
} while(numGuesses < 5);

if(numGuesses == 5) {
        alert('Sad! I lost!')
}
</script>
</body>
</html>
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
A Backwards Guessing Game For this assignment, you will be a making a guessing game with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

  • FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called...

    FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1, 5) print("You will have " + str(guess) + " guesses.") YourNumber = ??? unusedguesses=int(guess) while unusedguesses < guess:     if int(YourNumber) == number:         print("YAY, You have guessed my number")     else:         unusedguesses=int(guess)-1         if unusedguesses == 0:              break         else:             print("Try again!") print("The number was ", str(number))

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • on python i need to code a guessing game. After the player has guessed the random...

    on python i need to code a guessing game. After the player has guessed the random number correctly, prompt the user to enter their name. Record the names in a list along with how many tries it took them to reach the unknown number. Record the score for each name in another list. When the game is quit, show who won with the least amount of tries. this is what i have so far: #Guess The Number HW assignment import...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • python code for guessing game users enter the number the computer will guess 8:38 PM 100...

    python code for guessing game users enter the number the computer will guess 8:38 PM 100 nstructure.com 1. Number guessing game : (5 points) 1) Requirements: Your program will ask the user to enter a number between 1 and 1000. Then it will try to guess the correct number with the guaranteed minimal average number of guesses. Which search algorithm should you use? 2) Expected Output: Enter a number between 1 and 1000? 784 Computer guesses: 500 Type 'l' if...

  • Please write a C# program that where a player will play a guessing game with the...

    Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • Write a C++ program to play the number guessing game with user as follows.

    Write a C++ program to play the numberguessing game with user as follows.The user determines a number between 1~100.The program has 4 tries to guess the number byproviding a range (low, high) on each try.The user tells the program whether the number isbelow, within, or above the range.The program announces a game loss after 4 incorrecttries.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT