Case Statement (Integer)

<html>
<head>

<script type='text/javascript'>
// This program allows a user to choose a number between one and three to win
// either a brand new sports car or a goat. Each number corresponds to a door behind
// which is either the car or a goat. But there is only one car and two goats.

var Number = 0 ;

Number = prompt ('What door do you choose?') ;
Number = parseInt(Number) ;
// The parseInt function will convert the character input to an integer

switch (Number)
{ // begin switch

case 1:
{ // begin case 1
alert ('A Goat - Hard Luck') ;
break ;
} // end case 1

case 2:
{ // begin case 2
alert ('A brand new sports car - Well Done') ;
break ;
} // end case 2

case 3:
{ // begin case 3
alert ('A Goat - Hard Luck') ;
break ;
} // end case 3

default :
{ // begin default
alert ('You MUST Choose either 1, 2 or 3 - Press F5 to refresh the page.') ;
} // end default

} // end switch

</script>
</head>
<body>
</body>
</html>

Next: Case Statement (Character)