The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 10


Code Explanation

if (ac>0) { if statement to determine if there
were any aces

if ((sumup+10)<=21) { If so, asks if making one of the aces
take on the value of 11 still yield a
total less than 21

sumup +=10; If yes, do it

} Closes inner if

} Closes outer if

housetotal = sumup; Sets the global variable to be the
sum

if (sumup<17) { Asks if the sum is under 17

return true; Returns true if so, meaning its OK
to get one more card

} Closes clause

else { Begins else clause

return false; Return false, meaning the dealer
won't get another card

} Closes the else clause

} Closes the function

function dealfromdeck(who) { Header for the function to deal from
the deck

var card; Holds the card

var ch = 0; Holds the index for the next undealt
card

while ((deck[ch].dealt>0)&&(ch<51)) { Asks if this card has been dealt

ch++; Increases ch to go on to the next
card
Free download pdf