Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Last active March 16, 2023 19:11
Show Gist options
  • Save sandrabosk/46e7505a399d776f9f4c025efbcacf70 to your computer and use it in GitHub Desktop.
Save sandrabosk/46e7505a399d776f9f4c025efbcacf70 to your computer and use it in GitHub Desktop.

Checking for understanding - switch

Challenge 1

Create a new variable called language . Then create a conditional that handles printing:

  • Hola, Martin if language is equal to "spanish"
  • Salut, Martin if language is equal to "french"
  • Hello, Martin if language is equal to "english"
  • I am not sure what are you trying to do, sorry! 🍺 if language is equal to anything else.

Bonus: Use prompts to determine what language will be set to as well as the name that should be consoled.

Hint: For bonus part, you have to use repl.it with HTML, CSS and JS, instead only with JS.

Challenge 2

Write a program that asks the user to enter a number between 1 and 7 (inclusive) and then displays the corresponding day of the week.

For example, if the user enters 1, the program should output "Monday"; if the user enters 2, the program should output "Tuesday"; and so on.

To accomplish this, you can use a switch statement with cases for each possible input value, and a default case to handle invalid inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment