Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created April 3, 2020 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidPeralvarez/7342f2c9c7966a32482cafe9a94136fb to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/7342f2c9c7966a32482cafe9a94136fb to your computer and use it in GitHub Desktop.
JavaScript - switch
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
var numero = 3,
producto;
// if ( numero === 1 ) {
// producto = 'chocolatina';
// } else if ( numero === 2 ) {
// producto = 'bolsa de patatas';
// } else if ( numero === 3 ) {
// producto = 'galletas';
// } else {
// producto = 'incorrecto';
// }
switch ( numero ) {
case 1:
producto = 'chocolatina';
break;
case 2:
producto = 'bolsa de patatas';
break;
case 3:
producto = 'galletas';
break;
default:
producto = 'incorrecto';
}
console.log( 'Has elegido el producto: ' + producto );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment