Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active February 13, 2024 23:41
Show Gist options
  • Save ross-u/d43b75f298e4a2afd8832af856f07a57 to your computer and use it in GitHub Desktop.
Save ross-u/d43b75f298e4a2afd8832af856f07a57 to your computer and use it in GitHub Desktop.

JS | Conditionals and Loops

Custom "Hello World"! - Exercise

Let’s write an improved version of the ‘Hello, world!’ program. Let’s ask the user in which language they want to see the message. You must have, at least, three different languages.

  • If the user wants the message in Spanish, you have to log in the console “Hola, mundo!”.
  • If the user wants the message in French, you have to log in the console “Bonjour tout le monde”.
  • Finally, if we don’t have the indicated language, we will show “Hello, world!”.

Use the if…else and else if statements we have just learned

Syntax
if( condition ) {
 // do something
}
else if (condition ) {
  // do something else
} 
else {
  // do this previous conditions were not true
}

For this simple exercise you may use codepen.io or repl.it.

Use the code below as your starting point.

var userInput = prompt('What is your language?');
// Your code here ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment