/
Guess Games The three programs to look at are at: Guess Games The three programs to look at are at:

Guess Games The three programs to look at are at: - PowerPoint Presentation

conchita-marotz
conchita-marotz . @conchita-marotz
Follow
343 views
Uploaded On 2019-11-27

Guess Games The three programs to look at are at: - PPT Presentation

Guess Games The three programs to look at are at httpciswebbristolccedupgrocerCIS122S13loopsetcJSguessgameone5html httpciswebbristolccedupgrocerCIS122S13loopsetcJSguessgameonegame5html ID: 768347

guess quot document write quot guess write document therannum html myguess random number high var body math game generate

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Guess Games The three programs to look a..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Guess Games The three programs to look at are at: http://cisweb.bristolcc.edu/~pgrocer/CIS122S13/loopsetcJS/guessgameone5.html http://cisweb.bristolcc.edu/~pgrocer/CIS122S13/loopsetcJS/guessgameonegame5.html http://cisweb.bristolcc.edu/~pgrocer/CIS122S13/loopsetcJS/guessgamemulti5.html

start Generate random Guess R = G Got it R > G Low High End I generate a random number and prompt the user for a guess. Then I compare and process. Note this version allows for only one guess. Works best in Firefox

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript guess number game</title></head> <body><h1>GUESSING GAME</h1><script type="text/javascript"> var theRanNum = Math.floor(Math.random()*5)+1; document.write(theRanNum); document.write("<br>"); var myGuess = parseInt(window.prompt("Enter your quess")); if (theRanNum == myGuess) { document.write("You got it"); } else { if (theRanNum > myGuess) { document.write("Your guess is to low"); } else { document.write("Your guess is to high"); } }</script></body> </html> Note that I write theRanDum on the screen for testing purposes.

start Generate random Guess R = G Got it R > G Low High End Now I want to set up a loop to continue until the answer is correct. I have decided to use a do...while so the question will be at the bottom. Insert a decision here To continue if the guess was not correct. Loop back to just before the guess.

start Generate random Guess R = G Got it R > G Low High End R != G If the random number and the guess are not equal I go back and guess again. Note that != means not equal to. The do loop I am using will have the do right before the guess so that is the entry point when I loop back.

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript guess number game</title></head> <body><h1>GUESS GAME</h1><script type="text/javascript"> var theRanNum = Math.floor(Math.random()*5)+1; document.write(theRanNum); do { document.write("<br>"); var myGuess = parseInt(window.prompt("Enter your quess")); if (theRanNum == myGuess) { document.write("You got it"); } else { if (theRanNum > myGuess) { document.write("Your guess is to low"); } else { document.write("Your guess is to high"); } } } while (theRanNum != myGuess);</script></body></html> Note that the random number is generate once outside the do loop while the user guess is prompted when you look back for another try. I choose a do loop since I always want to do the loop at least once.

start Generate random Guess R = G Got it R > G Low High End R != G Now I need to give the user the opportunity to play again. I will put the question after I get a match. The entry point will come before I generate the random number so that each new game will have a new random number.

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript guess number game</title></head> <body><h1>GUESS GAME</h1><script type="text/javascript"> var theRanNum = Math.floor(Math.random()*5)+1; document.write(theRanNum); do { document.write("<br>"); var myGuess = parseInt(window.prompt("Enter your quess")); if (theRanNum == myGuess) { document.write("You got it"); } else { if (theRanNum > myGuess) { document.write("Your guess is to low"); } else { document.write("Your guess is to high"); } } } while (theRanNum != myGuess);</script></body></html> The do will go in here The prompt to ask the user about playing again and the question about the response will go here.

start Generate random Guess R = G Got it R > G Low High End R != G Prompt the user about playing again. The play again do loop comes in before the random number is generated. Play again Again != N

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript guess number game</title></head> <body><script type="text/javascript"> var playAgain = "Y"; do { var theRanNum = Math.floor(Math.random()*5)+1; document.write(theRanNum); do { document.write("<br>"); var myGuess = parseInt(window.prompt("Enter your quess")); if (theRanNum == myGuess) { document.write("You got it"); } else { if (theRanNum > myGuess) { document.write("Your guess is to low"); } else { document.write("Your guess is to high"); } } } while (theRanNum != myGuess); playAgain = window.prompt("Do you want to play again, Y or N"); document.write("<br>"); } while (playAgain != "N"); </script> </body> </html>