Last active
August 29, 2015 14:02
-
-
Save jfall76/9b1ea380272219b6f01c to your computer and use it in GitHub Desktop.
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"> | |
var guessingGame = function() { | |
var guess, answer, difference; | |
answer = 13; | |
guess = prompt("How many stripes on the US Flag?"); | |
while (isNaN(guess)) { | |
guess = prompt("You didn't not enter in a number \nHow many stripes are there on the US Flag?"); | |
} | |
difference = guess - answer; | |
if (guess == null) { | |
return "You can't even be bothered to try and make a guess?\nYou're no fun!"; | |
} else if (guess == 13) { | |
return "You are correct!\nThe 13 stripes represent the original 13 colonies of the United States of America"; | |
} else if (guess < 0) { | |
return "Okay buddy, a flag can't have a negative number of stripes!"; | |
} else if (guess > 100) { | |
return "You are way off.\nHow many flags do you know of that have hundreds of stripes on them?" | |
} else if ( guess <= 100 && guess >= 50) { | |
return "That's still pretty high. Try a much smaller number."; | |
} else if (guess < 50 && guess >= 25) { | |
return "You are getting warmer, but it's still a bit high."; | |
} else if (guess < 25 && guess >= 20) { | |
return "Getting warmer."; | |
} else if ((guess >= 0 && guess < 13) || (guess < 20 || guess >= 14)) { | |
return "You are super close now. You are only off by " + Math.abs(difference) + "."; | |
} | |
} | |
numofguesses = prompt("How many guesses would you like to have?"); | |
for (tries = 0; tries < numofguesses; tries++) { | |
alert(guessingGame()); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment