Created
June 9, 2014 00:58
-
-
Save petemmitchell/c5fe64685fb7e0f3df46 to your computer and use it in GitHub Desktop.
CodeFellows F1: Project 2 (Guessing game w/ For loop)
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 answer; | |
| var guessingGame = function(answer) { | |
| var guess, difference; | |
| guess = prompt("I'm thinking of a number between 1 & 20. Can you guess what it is?") | |
| difference = Math.abs(guess - answer) | |
| if(guess == answer) { | |
| alert("You win a new car!") | |
| return; | |
| } | |
| else | |
| if (difference >= 6) { | |
| alert("You're getting cold.") | |
| } | |
| else | |
| if (difference >= 3 && difference <= 5) { | |
| alert("You're getting warm.") | |
| } | |
| else | |
| if (difference >= 1 && difference <= 2) { | |
| alert("You're getting hot.") | |
| } | |
| } | |
| answer = Math.floor(Math.random() * 20) | |
| for (tries = 1; tries < 4; tries++) { | |
| result = guessingGame(answer) | |
| alert(result); | |
| } | |
| </script> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure why I'm getting the 2nd alert with "undefined". Been trying to work it out, but it's a head-scratcher.