Last active
August 29, 2015 14:02
-
-
Save macikokoro/9ef4443546fbbc9427c8 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
<script> | |
var random, result; | |
var findDifference = function(answer, guess) { | |
if (answer > guess) { | |
return answer - guess; | |
} | |
else { | |
return guess - answer; | |
} | |
} | |
var guessingGame = function(answer) { | |
var guess, difference; | |
guess = prompt("What number am I thinking about?"); | |
difference = findDifference(answer, guess); | |
if (parseInt(guess) === answer) { | |
console.log("That was impressive!"); | |
return "How did you do that?" | |
} | |
else { | |
return "Wrong again! You are off by :" + difference; | |
} | |
} | |
random = Math.floor(Math.random() * 20) | |
for (tries = 1; tries < 8; tries++) { | |
result = guessingGame(random) | |
alert(result); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment