Created
May 2, 2016 22:49
-
-
Save sanakm/2de7e699bafb70f42bafc278ceb18c09 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 game = { | |
userAmount: 100, | |
bet: null, | |
number: null, | |
guess: null, | |
getBetAmount: function() { | |
this.bet = parseInt(prompt("Please enter a bet:"),10); | |
if (this.bet > this.userAmount) { | |
alert("Bet amount cannot be larger than what's in your wallet!"); | |
} | |
else{ | |
this.userAmount -= this.bet; | |
this.getGuess(); | |
} | |
}, | |
getGuess: function() { | |
this.generateRand(); | |
this.guess = parseInt(prompt("Please enter a number:"),10); | |
console.log(this.guess); | |
this.checkGuess(); | |
}, | |
generateRand: function() { | |
this.number = Math.floor(Math.random() * 10); | |
console.log(this.number); | |
}, | |
checkGuess: function() { | |
if (this.guess === this.number) { | |
this.userAmount += (this.bet * 2) | |
console.log("Yay!") | |
alert("You were correct, you have " + this.userAmount + " in your wallet now"); | |
} | |
else if ((this.guess + 1 || this.guess - 1) === this.number) { | |
this.userAmount += this.bet | |
console.log("Not bad!") | |
alert("You were close. Here's your bet back."); | |
} | |
else { | |
console.log("Boo!"); | |
alert("WRONG AGAIN. You have " + this.userAmount + " in your wallet now"); | |
} | |
} | |
}; | |
while (game.userAmount > 0) { | |
game.getBetAmount(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment