Created
June 8, 2014 23:27
-
-
Save AnnemarieWegley/5d6c33942e1fc965edaf 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 random, result; | |
var findDifference = function(answer, guess) { | |
if (answer > guess) { | |
return answer - guess; | |
} | |
else { | |
return guess - answer; | |
} | |
} | |
var guessingTootsie = function(answer) { | |
var guess, difference; | |
guess = prompt("How many licks does it take to get to the inside of the Tootsie Pop?"); | |
difference = findDifference(answer, guess); | |
if (parseInt(guess) === answer) { | |
console.log("You got to the center"); | |
return "You win! You got to the center quick!"; | |
} | |
else { | |
return "Keep on guessing: " + difference; | |
} | |
} | |
random = Math.floor(Math.random() * 10) | |
for (tries = 1; tries < 4; tries++) { | |
result = guessingTootsie(random) | |
alert(result); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment