Last active
November 24, 2015 04:47
-
-
Save martinlaws/e6c5e40c0623000d70b1 to your computer and use it in GitHub Desktop.
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 lang="en"> | |
| <head> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | |
| </head> | |
| <body> | |
| <h1>Welcome to the <em>Fancy Betting Game</em>!</h1> | |
| <p id='wallet'></p> | |
| <button id='gogogo'>Let's go!</button> | |
| <button id='restart'>Restart!</button> | |
| <script src="main.js"></script> | |
| </body> |
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
| pot = 50; | |
| var ask = function() { | |
| var bet = Number(prompt('How much would you like to bet?')); | |
| if(bet <= wallet) { | |
| var guess = prompt('What\'s your best guess?'); | |
| var answer = (Math.floor(Math.random() * 10) + 1); | |
| if(guess <= 10){ | |
| if(guess == answer) { | |
| alert('correct!'); | |
| pot = pot + bet; | |
| alert('you have ' + pot + 'cashmoneys remaining'); | |
| } else { | |
| alert('wrong! ' + 'the correct answer was ' + answer); | |
| pot -= bet; | |
| alert('you have ' + pot + " " + 'cashmoneys remaining'); | |
| } | |
| } else { | |
| alert('that guess is WAY too high'); | |
| } | |
| } else { | |
| alert('That bet is NOT going to fly!') | |
| }; | |
| }; | |
| $(document).ready(function() { | |
| $('#wallet').text('You have ' + pot + ' dollars to spend.'); | |
| $('#gogogo').on('click', function() { | |
| ask(); | |
| $('#wallet').text('You have ' + pot + ' dollars to spend.'); | |
| }); | |
| $('#restart').on('click', function() { | |
| pot = 50; | |
| $('#wallet').text('You have ' + pot + ' dollars to spend.'); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment