Skip to content

Instantly share code, notes, and snippets.

@AnnemarieWegley
Created June 8, 2014 23:27
Show Gist options
  • Save AnnemarieWegley/5d6c33942e1fc965edaf to your computer and use it in GitHub Desktop.
Save AnnemarieWegley/5d6c33942e1fc965edaf to your computer and use it in GitHub Desktop.
<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