Money

The player can decide the size of their bet by selecting radio buttons. For the "Choose your own value", different alerts pop up if the player enters an invalid amount, less than 1, more than they have, or has a decimal in it. If the player clicks cancel, it automatically selects the first radio button.

Blackjack.js -- Entering amount of money to bet
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function chooseMoney() {    // When the player clicks on the radio button to choose their own amount
    // Their input is verified that the amount is valid (eg The amount is a number)
    yourMoneyTotal = parseInt(document.blackJack.yourMoneyTotal.value)
    yourMoneyBet = 0
         
    while ((yourMoneyBet == 0) || (yourMoneyBet == "") || (yourMoneyBet < 1) || (yourMoneyBet > yourMoneyTotal) || (isNaN(yourMoneyBet)) || (yourMoneyBet.indexOf(".") > 0)) {
        yourMoneyBet = prompt("How much money do you want to bet?","")
        document.blackJack.potMoney.value = yourMoneyBet
     
        if (yourMoneyBet == null) { // If the player decides to click cancel, their bet is set to the first radio button, $10
            document.blackJack.yourMoney[0].checked=true;
            yourMoneyBet = document.blackJack.yourMoney[0].value
        }
        else if ((yourMoneyBet == "") || (yourMoneyBet == "0") || (yourMoneyBet < "1")) {
            alert("You must bet at least $1.")
        }
        else if (isNaN(yourMoneyBet)) {
            alert("You cannot bet something that is not a number, that includes not adding in $ sign.")
        }
        else if (yourMoneyBet > yourMoneyTotal) {
            alert("You cannot bet more money than you have.")
        }
        else if (yourMoneyBet.indexOf(".") > 0) {
            alert("You cannot bet a number with a decimal in it.")
        }
    }
}
 
				function chooseMoney() {    // When the player clicks on the radio button to choose their own amount
					// Their input is verified that the amount is valid (eg The amount is a number)
					yourMoneyTotal = parseInt(document.blackJack.yourMoneyTotal.value)
					yourMoneyBet = 0
						
					while ((yourMoneyBet == 0) || (yourMoneyBet == "") || (yourMoneyBet < 1) || (yourMoneyBet > yourMoneyTotal) || (isNaN(yourMoneyBet)) || (yourMoneyBet.indexOf(".") > 0)) {
						yourMoneyBet = prompt("How much money do you want to bet?","")
						document.blackJack.potMoney.value = yourMoneyBet
					
						if (yourMoneyBet == null) { // If the player decides to click cancel, their bet is set to the first radio button, $10
							document.blackJack.yourMoney[0].checked=true;
							yourMoneyBet = document.blackJack.yourMoney[0].value
						}
						else if ((yourMoneyBet == "") || (yourMoneyBet == "0") || (yourMoneyBet < "1")) {
							alert("You must bet at least $1.")
						}
						else if (isNaN(yourMoneyBet)) {
							alert("You cannot bet something that is not a number, that includes not adding in $ sign.")
						}
						else if (yourMoneyBet > yourMoneyTotal) {
							alert("You cannot bet more money than you have.")
						}
						else if (yourMoneyBet.indexOf(".") > 0) {
							alert("You cannot bet a number with a decimal in it.")
						}
					}
				}
				

If there is not much money left, the computer will select the highest possible bet. When the player has less than $10, the player must enter in an amount.

Blackjack.js -- Check amount of money left
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
function checkMoney() { // Checks that the player has enough money to play again
    yourMoneyTotal = parseInt(document.blackJack.yourMoneyTotal.value)
    yourMoneyBet = parseInt(document.blackJack.potMoney.value)     
     
    // If the player has less than $50 left, then their bet is automatically chosen to the highest possible bet
    if (yourMoneyTotal < 50 && yourMoneyTotal >= 25) {
        document.blackJack.yourMoney[1].checked=true;
        document.blackJack.potMoney.value = document.blackJack.yourMoney[1].value
    }
    else if (yourMoneyTotal < 25 && yourMoneyTotal >= 10) {
        document.blackJack.yourMoney[0].checked=true;
        document.blackJack.potMoney.value = document.blackJack.yourMoney[0].value
    }
    else if (yourMoneyTotal < 10 && yourMoneyTotal > 0) {
        document.blackJack.yourMoney[4].checked=true;
        chooseMoney();
        document.blackJack.yourMoney[0].checked=false;
        document.blackJack.yourMoney[4].checked=true;
    }
    else if (yourMoneyTotal == 0 || yourMoneyTotal < 0) {   // If the player has gone bankrupt
        // They are given the option to play again
        playAgain();
    }
}
 
				function checkMoney() { // Checks that the player has enough money to play again
					yourMoneyTotal = parseInt(document.blackJack.yourMoneyTotal.value)
					yourMoneyBet = parseInt(document.blackJack.potMoney.value)      
					
					// If the player has less than $50 left, then their bet is automatically chosen to the highest possible bet
					if (yourMoneyTotal < 50 && yourMoneyTotal >= 25) {
						document.blackJack.yourMoney[1].checked=true;
						document.blackJack.potMoney.value = document.blackJack.yourMoney[1].value
					}
					else if (yourMoneyTotal < 25 && yourMoneyTotal >= 10) {
						document.blackJack.yourMoney[0].checked=true;
						document.blackJack.potMoney.value = document.blackJack.yourMoney[0].value
					}
					else if (yourMoneyTotal < 10 && yourMoneyTotal > 0) {
						document.blackJack.yourMoney[4].checked=true;
						chooseMoney();
						document.blackJack.yourMoney[0].checked=false;
						document.blackJack.yourMoney[4].checked=true;
					}
					else if (yourMoneyTotal == 0 || yourMoneyTotal < 0) {   // If the player has gone bankrupt
						// They are given the option to play again
						playAgain();
					}
				}