•Displays a heading that says "Please enter a door and I will give you your prize! Enter 1, 2 or 3."
•User enters a door number in a text box
•When they click a button that says "Show Prize", a Javascript function alerts them what they have won in a pop up box.
•Use a switch statement to alert them what they've won. It's up to you what their prize is! Example: "Congratulations! You have won a new car!"
•If the person did not enter 1, 2, or 3, alert "You lose because you can't follow directions!"
.
<script type="text/javascript">
function calculatePrize()
{var number = parseInt(document.getElementById('door').value);
switch (number) {
case '1': msg = "You won $1000.00"; break;
case '2': msg = "You won a vacation"; break;
case '3': msg = "You won a basket of spa products"; break;
}}
document.getElementById('door').value = ' Your prize is: ';
alert(msg);
</script>
</head>
<body>
<p>"Please enter a door and I will give you your prize! Enter 1, 2 or 3."
<br />
<input type='text' id='door' /> <br />
<input type="button" id="prize"
value="Display Prize" onclick='calculateSPrize()'/></p>

New Topic/Question
Reply


MultiQuote




|