Last active
August 29, 2015 14:22
-
-
Save josephhays/54d719d904268de21a84 to your computer and use it in GitHub Desktop.
Javascript Betting Game Assignment for LighthouseLabs
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
$(document).ready(function(){ | |
function startGame(evt) { | |
evt.preventDefault(); | |
var answer = Math.floor((Math.random() * 10) + 1); | |
var guess = $('#guess').val(); | |
var bet = $('#bet').val(); | |
var wallet = $('#wallet'); | |
var display = $('#display'); | |
display.empty(); | |
if (guess == answer) { | |
display.append('<strong>RIGHT ON THE SHNOZ! WE GOT A WINNER!</strong>'); | |
} else if (guess == (answer + 1) || guess == (answer - 1)) { | |
display.append('Close, but no cigar! You off by one! (The answer was ' + answer + ')'); | |
} else { | |
display.append('<em>Sorry, boy, you lost!</em> (The answer was ' + answer + ')'); | |
wallet.text(parseInt(wallet.text()) - bet); | |
}; | |
}; | |
console.log(wallet.text()); | |
if (parseInt(wallet) < 5) { | |
$('#placebet').replaceWith("Game over! You suck!"); | |
} | |
$('#placebet').on('click', startGame); | |
}); |
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> | |
<title>betting game</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> | |
<script src="game.js"></script> | |
</head> | |
<body> | |
<h1> Betting Game </h1> | |
<p> | |
I'm betting $ | |
<input placeholder="how much? [Between 5 and 10 please.]" type="number" id="bet" value="5"> | |
<label>on that there numbah'</label> | |
<input placeholder="5? maybe 6?" type="number" id="guess" value="5"> | |
<button id="placebet">Place bet</button> | |
<div id="display"> | |
<p>Place your bets, left, right, and center!</p> | |
</div> | |
<div id="wallet"> | |
100 | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment