Created
June 11, 2014 19:18
-
-
Save jfall76/bc6b28bae6e8d86a404c to your computer and use it in GitHub Desktop.
GameObject.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script type="text/javascript"> | |
function Guess(guess, tries) { | |
this.guess = guess; | |
this.tries = tries; | |
this.message | |
this.answer = false; | |
this.run = function() { | |
var difference, answer; | |
answer = 13; | |
difference = this.guess - answer; | |
this.tries = this.tries - 1; | |
if (this.guess == null) { | |
this.message = "You can't even be bothered to try and make a guess?\nYou're no fun!"; | |
} else if (this.guess == 13) { | |
this.message = "You are correct!\nThe 13 stripes represent the original 13 colonies of the United States of America"; | |
this.answer = true; | |
} else if (this.guess < 0) { | |
this.message = "Okay buddy, a flag can't have a negative number of stripes!"; | |
} else if (this.guess > 100) { | |
this.message = "You are way off.\nHow many flags do you know of that have hundreds of stripes on them?" | |
} else if ( this.guess <= 100 && this.guess >= 50) { | |
this.message = "That's still pretty high. Try a much smaller number."; | |
} else if (this.guess < 50 && this.guess >= 25) { | |
this.message = "You are getting warmer, but it's still a bit high."; | |
} else if (this.guess < 25 && this.guess >= 20) { | |
this.message = "Getting warmer."; | |
} else if ((this.guess >= 0 && this.guess < 13) || (this.guess < 20 || this.guess >= 14)) { | |
this.message = "You are super close now. You are only off by " + Math.abs(difference) + "."; | |
} | |
} | |
} | |
person = new Guess(0, 0); | |
person.tries = prompt("How many guesses would you like to have?"); | |
while (isNaN(person.tries)) { | |
person.tries = prompt("That was not a number.\nHow many guesses would you like to have?"); | |
} | |
do { | |
person.guess = prompt("How many stripes are there on the US Flag?"); | |
person.run(); | |
alert(person.message); | |
} while ((person.tries > 0) && (person.answer == false)); | |
if (person.answer) { | |
alert("You won!"); | |
} else { | |
alert("Sorry, you are all out of guesses.\nBetter luck next time!") | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment