Created
June 1, 2016 12:43
-
-
Save adrimolano/a9efdbd8d484adb85fca9d38654613a2 to your computer and use it in GitHub Desktop.
game
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
| @charset "UTF-8"; | |
| /* CSS Document */ | |
| body { | |
| font-family: 'Open Sans', sans-serif; | |
| font-size: 16px; | |
| font-weight: 100; | |
| background-image: url(../images/body.jpg); | |
| background-attachment: fixed; | |
| background-size: cover; | |
| color: #000; | |
| line-height: 1.6; | |
| } | |
| h1 { | |
| font-family: 'Roboto', sans-serif; | |
| font-weight: 100; | |
| font-size: 50px; | |
| text-transform: uppercase; | |
| letter-spacing: 14px; | |
| } | |
| h2 { | |
| font-family: 'Roboto', sans-serif; | |
| font-weight: 100; | |
| font-size: 36px; | |
| text-transform: uppercase; | |
| } | |
| ul { | |
| margin: 0; | |
| padding: 0px; | |
| list-style: none; | |
| } | |
| input { | |
| font-family: 'Open Sans', sans-serif; | |
| font-size: 16px; | |
| } | |
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
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Game</title> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
| <link rel="stylesheet" type="text/css" href="game.css"> | |
| </head> | |
| <body style="text-align:center;"> | |
| <h2>Bankroll:: $<span id="balance"></span></h2> | |
| <form> | |
| <label for="apuesta">Apuesta ::</label> | |
| <input id="apuesta" name="apuesta" type="text" placeholder="Amount" /> | |
| <br/><br/> | |
| <label for="guess">Guess ::</label> | |
| <input id="guess" name="guess" type="text" placeholder="Number from 1-10" /> | |
| <br/><br/> | |
| <input type="button" id="submit" name="submit" value="Apuesta"/> | |
| </form> | |
| <script type="text/javascript" src="game.js"></script> | |
| </body> | |
| </html> | |
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
| // JavaScript Document:( | |
| $(document).ready(function(){ | |
| $('#submit').on('click', gameBegins); | |
| }); | |
| $(document).ready(function(){ | |
| update_bankroll(); | |
| }); | |
| var game = { | |
| apuesta: null, | |
| bankroll: 100, | |
| randNumber: null, | |
| numberGuess: null, | |
| getapuestaAmount: function() { | |
| return this.apuesta = parseInt($('#apuesta').val()); | |
| }, | |
| getRandomNumber: function(min, max) { | |
| return this.randNumber = Math.floor(Math.random()*(max-min+1)+min); | |
| }, | |
| getNumberGuess: function() { | |
| return this.numberGuess = parseInt($('#guess').val()); | |
| }, | |
| }; | |
| function gameBegins() { | |
| game.getapuestaAmount(); | |
| game.getRandomNumber(1,10); | |
| game.getNumberGuess(); | |
| console.log("randNum:" + game.randNumber + " - guess: " + game.numberGuess); | |
| if(game.apuesta > game.bankroll) { | |
| alert("apuesta es mayor que tu $"); | |
| game.getapuestaAmount(); | |
| } | |
| else{ | |
| game.bankroll -= game.apuesta; | |
| update_bankroll(); | |
| if(game.randNumber === game.numberGuess) { | |
| alert("Yay" + (game.apuesta * 2) + " !" ); | |
| game.bankroll += (game.apuesta * 2); | |
| console.log(game.bankroll); | |
| update_bankroll(); | |
| } | |
| else if((game.numberGuess + 1 || game.numberGuess -1) === game.randNumber){ | |
| alert("Nope!"); | |
| game.bankroll += game.apuesta; | |
| console.log(game.bankroll); | |
| update_bankroll(); | |
| } | |
| else{ | |
| alert(":("); | |
| console.log(game.bankroll); | |
| update_bankroll(); | |
| } | |
| } | |
| } | |
| function update_bankroll(){ | |
| document.querySelector('#balance').innerHTML = game.bankroll; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment