Created
June 9, 2014 21:42
-
-
Save PlenipotentSS/01ddd3eaa236dfbc88ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <script> | |
| var feet, result, var tries; | |
| var findDifference = function(answer, guess) { | |
| if (answer > guess) { | |
| return answer - guess; | |
| } | |
| else { | |
| return guess-answer; | |
| } | |
| } | |
| var guessingGame = function(answer) { | |
| var guess, difference; | |
| guess = prompt("How many feet tall is the Spaceneedle"); | |
| difference = findDifference(answer, guess); | |
| if (parseInt(guess)=== answer) { | |
| ; | |
| return "You win!!!"; | |
| } | |
| else { | |
| return "Off by: " + difference; | |
| } | |
| } | |
| feet = 605 | |
| tries = 0 | |
| while ( tries < 4 ) { | |
| result = guessingGame(feet) | |
| alert(result); | |
| tries++; | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment