Question

Computer Guesses - Create a page that allows the user to think of a number from 1 to 100. Write a function that will guess the number the user chose. The user will provide clues: higher or lower and correct. It should take no more than 7 guesses to get the correct number.

User Guesses - Create a page that generates a random number from 1 to 100. Allow the user only 7 guesses to guess the number. Provide clues: higher or lower and correct.

Go to the user guess page Think of a number between 1 and 100 Guess 1: 52 → Lower Guess 2: 26 → Higher Guess 3:39 Hurray! I g Both pages have to link together were you can switch between the two using a button. In HTML.

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

Please Let me know if you need more information:-
===========================================
User Guesses - TRY
=========================================

<html>
<script>
var numGeneratedByComputer;
var guessessMadeByUser = 1;

function generateNum(){
   guessessMadeByUser = 1;
   numGeneratedByComputer = Math.floor(Math.random() * 101);
   document.getElementById("numFromUser").value = null;
   document.getElementById("dynaMic").innerHTML = "";
}

function guessCheck(){

var input = parseInt(document.getElementById("numFromUser").value);
var textToUser = "Guess " + guessessMadeByUser +":"+ input;

if(guessessMadeByUser > 7){
   document.getElementById("dynaMic").innerHTML = "Oops! you tries exhausted.<br>Please click on Play Again<br>";
   return;
}

if(input < numGeneratedByComputer){
   textToUser += ' --> Lower';
}else if (input > numGeneratedByComputer){
   textToUser += ' --> Higher';
}else if (input == numGeneratedByComputer){
   textToUser += "<br>Hurray! you got in "+ guessessMadeByUser +" guesses!";
}
document.getElementById("dynaMic").innerHTML += textToUser + "<br>";
guessessMadeByUser +=1;

}
</script>

<body onload="generateNum()">
<a href="./UserGenerated.html"> Goto Computer guess page </a>
<div style="width: 50%;
   text-align: center;
height: 50%;
background-color: lightgray;">
<label style="color:blue; font-size: 22px;"><b>Think of a number between 1 - 100</b></label><br><br>
<div style="background-color: white;
margin-left: 20%;
margin-right: 20%;
height: 60%;">
<label style="background-color: yellow;"> Guess the Number generated by Computer</label><br>
<div id="dynaMic" style="background-color: lightcyan;
height: 60%;
width: 75%;
   overflow-x: scroll;
   margin-bottom: 2%;
margin-left: 10%;">

</div>
<input type="number" id="numFromUser" placeholder="Enter the num guess" >
<button type="button" name="guess" onClick="guessCheck()">Guess</button>
<button type="button" name="guess" onClick="generateNum()">Play Again</button>
</div>
</div>

</body>
</html>
======================================


COMPUTER GUESSES:-
=========================================

<html>
<script>
var numGeneratedByComputer;
var guessessMadeByComputer = 1;
min =1
max = 100;

function generateNum(){
   guessessMadeByComputer = 1;
   document.getElementById("fromUser").value = null;
   document.getElementById("dynaMic").innerHTML = "";
}


function guessCheck(){

if(guessessMadeByComputer > 7){
   document.getElementById("dynaMic").innerHTML = "Oops! Computer tries exhausted.<br>Please click on Play Again<br>";
   return;
}

var input = document.getElementById("fromUser").value;

if(input == "higher"){
max = numGeneratedByComputer;
}else if(input == "lower"){
min = numGeneratedByComputer;
}else if(input == "correct"){
document.getElementById("dynaMic").innerHTML = "<br>Hurray! Computer got in "+ guessessMadeByComputer +" guesses!"
}
numGeneratedByComputer = Math.floor(Math.random() * (+max - +min) + +min );
var textToUser = "Guess From Computer " + guessessMadeByComputer +":" + numGeneratedByComputer;
document.getElementById("dynaMic").innerHTML += textToUser + "<br>";
guessessMadeByComputer +=1;

}
</script>

<body onload="generateNum()">
<a href="./ComputerGenerated.html"> Goto User guess page </a>
<div style="width: 50%;
   text-align: center;
height: 50%;
background-color: lightgray;">
<label style="color:blue; font-size: 22px;"><b>Think of a number between 1 - 100</b></label><br><br>
<div style="background-color: white;
margin-left: 20%;
margin-right: 20%;
height: 60%;">
<label style="background-color: yellow;"> Computer Guess </label><br>
<div id="dynaMic" style="background-color: lightcyan;
height: 60%;
width: 75%;
   overflow-x: scroll;
   margin-bottom: 2%;
margin-left: 10%;">

</div>
<input type="text" id="fromUser" placeholder="Enter lower/higher/correct" >
<button type="button" name="guess" onClick="guessCheck()">GetComputerGuess</button>
<button type="button" name="guess" onClick="generateNum()">Play Again</button>
</div>
</div>

</body>
</html>

====================================
OUTPUT:-
======================================
Think of a number between 1 - 100 Guess the Number generated by Computer Enter the num guess Guess Play Again

=====

Think of a number between 1 - 100 Guess the Number generated by Computer Guess 1:34 --> Lower Guess 2:89 --> Higher Guess 3:6

=========

Second case:-
================

Think of a number between 1 - 100 Computer Guess Enter lower/higher/correct GetComputerGuess Play Again

======

Think of a number between 1 - 100 Computer Guess Hurray! Computer got in 5 guesses!Guess From Computer 5:56 correct GetComput

====

Thanks

Think of a number between 1 - 100 Guess the Number generated by Computer Enter the num guess Guess Play Again

Think of a number between 1 - 100 Guess the Number generated by Computer Guess 1:34 --> Lower Guess 2:89 --> Higher Guess 3:65 --> Lower Guess 4:85 --> Higher Guess 5:82 Hurray! you got in 5 guesses! 82 Guess Play Again

Think of a number between 1 - 100 Computer Guess Enter lower/higher/correct GetComputerGuess Play Again

Think of a number between 1 - 100 Computer Guess Hurray! Computer got in 5 guesses!Guess From Computer 5:56 correct GetComputerGuess Play Again

Add a comment
Know the answer?
Add Answer to:
Computer Guesses - Create a page that allows the user to think of a number from...
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
  • Using a list, create a game that allows a user 3 guesses. You should consider a...

    Using a list, create a game that allows a user 3 guesses. You should consider a list of 5 items (you can consider any list you want, e.g. a list of 5 different foods’ names).   You are to create a game that asks a user to make 3 guesses. Track the guesses and what the guess was. Provide a code that tracks all user guesses and counts those guesses. I want to create a simple code that allows the user to...

  • Write a program that allows a user to play a guessing game. Pick a random number...

    Write a program that allows a user to play a guessing game. Pick a random number in between 1 and 100, and then prompt the user for a guess. For their first guess, if it’s not correct, respond to the user that their guess was “hot.” For all subsequent guesses, respond that the user was “hot”if their new guess is strictly closer to the secret number than their old guess and respond with“cold”, otherwise. Continue getting guesses from the user...

  • Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it)...

    Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it) Program should be able to guess correctly in 7 tries or lower. Initialize a variable that represents the lowest possible number to 0 (what type should this be?) Initialize a variable that represent the highest possible number to 100 (what type should this be?) Initialize a Boolean variable that represents if we’ve achieved the correct guess to false Initialize a variable in which to...

  • Specification Write a program that allows the user to play number guessing games. Playing a Guessing...

    Specification Write a program that allows the user to play number guessing games. Playing a Guessing Game Use rand() function from the Standard C Library to generate a random number between 1 and 100 (inclusive). Prompt the user to enter a guess. Loop until the user guesses the random number or enters a sentinel value (-1) to give up. Print an error message if the user enters a number that is not between 1 and 100. Print an error message...

  • Create a HTML with Java Script such that you input a number between 222 and 333....

    Create a HTML with Java Script such that you input a number between 222 and 333. Then the user needs to guess the number. If the user’s guess is higher than the number, the program should display “Too high, try again.” If the user’s guess is lower than the number, the program should display “Too low, try again.” If the difference is less than 10, it should also mention "too close". When the user guesses the number, the program should...

  • Write a program to play "guess my number". The program should generate a random number between...

    Write a program to play "guess my number". The program should generate a random number between 0 and 100 and then prompt the user to guess the number. If the user guesses incorrectly the program gives the user a hint using the words 'higher' or 'lower' (as shown in the sample output). It prints a message 'Yes - it is' if the guessed number is same as the random number generated. ANSWER IN C LANGUAGE. ====================== Sample Input / Output:...

  • Using a list, create a game that allows a user 3 guesses. You should consider a list of 5 items (you can consider any list you want, e.g. a list of 5 different foods’ names). You are to create a game...

    Using a list, create a game that allows a user 3 guesses. You should consider a list of 5 items (you can consider any list you want, e.g. a list of 5 different foods’ names). You are to create a game that asks a user to make 3 guesses. Track the guesses and what the guess was. Provide a code in C language that tracks all user guesses and counts those guesses.

  • How can I do this program complete with input validation so that the computer prompts the...

    How can I do this program complete with input validation so that the computer prompts the user to enter a number 0 through 100 if he/she guesses anything lower than 0, a floating point number, or other characters? And later, prompts the user to enter yes or no if he/she enters anything else when the program prompts the user to play again? Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number...

  • Required in JAVA language Write a program that enables a user to play number guessing games....

    Required in JAVA language Write a program that enables a user to play number guessing games. The following is a nutshell description of a number guessing game. + a random number is generated + loop prompting the user to enter guesses until the user guesses the number or hits the maximum number of allowed guesses or enters the "quit" sentinel value The rest of this specification documents number guessing games in more detail. The documentation uses manifest constants that can...

  • Write a C program that asks the user to think of an integer number from 1...

    Write a C program that asks the user to think of an integer number from 1 to 20. Have the computer guess what the number is by using a binary tree to determine the next guess. You can create the binary tree “by hand” by typing in a set of malloc commands and explicitly linking the nodes. (make the tree completely, then traverse the tree) Use a menu to provide the user with a selection to answer the results of...

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