Created
November 6, 2014 03:39
-
-
Save mathowie/e40cf4dd8dee6830f7ec 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
var userNum, computerNum, message; | |
userNum = Number(prompt("Pick a number between 1 and 10!")); | |
computerNum = (Math.floor(Math.random() * 10)) + 1; | |
//sanitize input then Check guess | |
if (userNum >= 11) { | |
message = "Too high of a number, please refresh and pick again!"; | |
} else if (isNaN(userNum)) { | |
message = "This is not a number, please refresh and pick again!"; | |
} else if (userNum === computerNum) { | |
message = "You are correct sir!"; | |
} else if (userNum + 1 === computerNum || userNum - 1 === computerNum) { | |
message = "So close! It was " + computerNum; | |
} else { | |
message = "Sorry, it was " + computerNum; | |
} | |
alert(message); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment