Skip to content

Instantly share code, notes, and snippets.

@mathowie
Created November 6, 2014 03:39
Show Gist options
  • Save mathowie/e40cf4dd8dee6830f7ec to your computer and use it in GitHub Desktop.
Save mathowie/e40cf4dd8dee6830f7ec to your computer and use it in GitHub Desktop.
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