The Essential Guide to HTML5

(Greg DeLong) #1

DICE GAME


case 11: .. or 11


document.f.outcome.value="You
win!";


Display You win!

break; Exit the switch


case 2: For 2,


case 3: .. or 3


case 12: .. or 12


document.f.outcome.value="You
lose!";


Display You lose!

break; Exit the switch


default: For anything else


point = sum; Save the sum in the variable point


document.f.pv.value=point; Display the point value


firstturn = false; Set firstturn to false


document.f.stage.value="Need
follow-up throw.";


Display Need follow-up throw

document.f.outcome.value=" "; Erase (clear) the outcome field


} End the switch


} End the if-true clause


else { Else (not a first turn)


switch(sum) { Start the switch, again using sum


case point: if sum is equal to whatever is in
point


document.f.outcome.value="You win!"; Display You win!

Free download pdf