Exercise 30 refer to the following code:
var vacation = prompt("What do you want to do during Spring Break? ↵
Type S for skiing, F for fishing, H for hiking,8 J for learning JavaScript.", " ");
if (vacation == 'S')
document.write("You should go to Aspen.<br />");
if (vacation == 'H')
document.write("Be sure to buy good hiking boots.<br />");
if (vacation == 'F')
document.write("Worms make good bait.<br />");
if (vacation == 'J')
document.write("You're gonna have soooo much fun!<br />");
30. Rewrite the code using a switch statement.
Here I am providing the code and the output for the problem.
Code:-
Output:-
Code in text format:-
<!DOCTYPE html>
<html>
<body>
<script>
var vacation = prompt("What do you want to do during Spring Break?
Type S for skiing, F for fishing, H for hiking,8 J for learning
JavaScript.");
switch (vacation) { //taking the input from user and enters the
users input to the switch statement
case "S":
document.write("You should go to Aspen.<br />"); //if user
enters "S"
break;
case "F":
document.write("Worms make good bait.<br />"); //if user
enters "F"
break;
case "H":
document.write("Be sure to buy good hiking boots.<br />");
//if user enters "H"
break;
case "J":
document.write("You're gonna have soooo much fun!<br />");
//if user enters "J"
break;
}
</script>
</body>
</html>
Exercise 30 refer to the following code: var vacation = prompt("What do you want to do...