I'm trying to switch my console.log()/prompt based javascript game into a visual playable game for browsers. So to do this, I'm mixing in jQuery with my javascript.
1) I'm trying to set nHands = 1, 2, or 3 based on which button that the user clicks on. I have 3 buttons with the same class of .smallbutton, and unique classes of .oneh .twoh and .threeh.
2) After the user clicks on any one of the 3 buttons, all the buttons will disappear, with the use of $('.smallbutton').detach();. This works fine.
The Problem is with 1) above. It does not seem to set nHands = to anything. Because in order for my recordBetAmount(); to run/do something, it needs to be set equal to 1,2,or 3. Why is nHands not being set equal to anything?
Here's the fiddle http://jsfiddle.net/cL9dx/ . Please note that the fiddle includes the second way I tried.
Here's the relevant part of my code:
var hand1, hand2, hand3, hD, nHands; //global vars
function numHands() {
$('<p>Choose the number of hands you want to play.</p>').appendTo('.message');
$('.oneh').click(function () {
nHands = 1;
$('.smallbutton').detach();
});
$('.twoh').click(function () {
nHands = 2;
$('.smallbutton').detach();
});
$('.threeh').click(function () {
nHands = 3;
$('.smallbutton').detach();
});
if (nHands > 0 && nHands < 4) {
x = 150000 / nHands;
if (nHands > 0) {
hand1 = new Hand("First Hand", x, x, ".hand1");
if (nHands > 1) {
hand2 = new Hand("Second Hand", x, x, ".hand2");
if (nHands > 2) {
hand3 = new Hand("Third Hand", x, x, ".hand3");
}
}
}
} else {
$('<p>ERROR!!!</p>').appendTo('.message');
}
}
....
numHands();
recordBetAmount();
edit: I've even tried making the above numHands function into two separate functions, but still doesn't seem to set nHands = to anything.