Blackjack (vs majority)
by Kiya_Iekret
HTML
Hand #1: <input type='number' id='hand1' min='6' max='21'/><br/>
Hand #2: <input type='number' id='hand2' min='6' max='21'/><br/>
Dealer: <input type='number' id='dealer' min='6' max='21'/><br/>
Majority Vote: <input type='number' id='majority' min='1' max='4'/><br/>
<button>Inflict math</button>
<button>Clear inputs</button>
<p>
best call: <span></span>
</p>
JavaScript
const inputs = [...document.getElementsByTagName('input')];
const output_slot = document.getElementsByTagName('span')[0];
const calc_trigger = document.getElementsByTagName('button')[0].addEventListener('click', () =>
{
let hand1 = inputs[0].value * 1;
let hand2 = inputs[1].value * 1;
let dealer = inputs[2].value * 1;
const vote = inputs[3].value;
const DRYLogicChecks = {
loseToDealerTwice: () =>
{if ((hand1 < dealer) && (hand2 < dealer)) {output_slot.innerText = "dealerino winnerino"};},
tieTwice: () => {if ((hand1 === dealer) && (hand2 === dealer)) {output_slot.innerText = "dealerino winnerino"};},
dealerAutoWin: () => {if(dealer === 21) {output_slot.innerText = "dealerino winnerino"};}
};
output_slot.innerText = "majority vote"
//7 magic number = 85/13, average value of a card
dealer = ((hand1 >= dealer)||(hand1 >= dealer))? dealer += 7 : dealer;
switch (vote)
{
case "1":
hand1 += 7;
hand2 += 7;
if ((hand1 > 21) && (hand2 > 21)) {output_slot.innerText = "dealerino winnerino"};
break;
case "2":
hand1 += 7;
if ((hand1 > 21) && (hand2 < dealer)) {output_slot.innerText = "dealerino winnerino"};
DRYLogicChecks.loseToDealerTwice();
break;
case "3":
hand2 += 7;
if ((hand1 < dealer) && (hand2 > 21)) {output_slot.innerText = "dealerino winnerino"};
DRYLogicChecks.loseToDealerTwice();
break;
case "4":
DRYLogicChecks.loseToDealerTwice();
break;
default:
output_slot.innerText = "u wot mate?";
break;
}
DRYLogicChecks.tieTwice();
DRYLogicChecks.dealerAutoWin();
});
//shotCaller(hand1_call, hand2_call);
//output_slot.innerText = 4
//below is good
const input_clear = document.getElementsByTagName('button')[1].addEventListener('click', () =>
{
inputs.forEach((dom_ele) =>
{
dom_ele.value = "";
});
output_slot.innerText = "";
});