-
-
Save DavidPeralvarez/7342f2c9c7966a32482cafe9a94136fb to your computer and use it in GitHub Desktop.
JavaScript - switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Curso de Javascript</title> | |
</head> | |
<body> | |
<script src="scripts.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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