Question

Exercise 30 refer to the following code: var vacation = prompt("What do you want to do...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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>

Add a comment
Know the answer?
Add Answer to:
Exercise 30 refer to the following code: var vacation = prompt("What do you want to do...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT