Last active
June 12, 2018 23:11
-
-
Save KattyaCuevas/41ccdfd7b87c2c369216 to your computer and use it in GitHub Desktop.
Ejemplos Taller de Fundamentos de JavaScript
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
console.log('Hola Profesor Xavier'); |
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
// Esto es un comentario | |
/* Y éste también | |
es un comentario */ | |
/* Se declara variable nombre */ | |
var nombre; | |
/* prompt permite el ingreso de datos y se le asigna el resultado | |
a la variable nombre */ | |
nombre = prompt('Cómo te haces llamar?'); | |
/* console.log imprime el resultado | |
con nuestra variable */ | |
console.log('Bienvenido a la Escuela Xavier ' | |
+ 'para Jóvenes Superdotados, ' | |
+ nombre); |
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
/* Declaración de variable clase */ | |
var clase = prompt('Qué clase te gusta más? (Genética, Manipulación de Energía, Educación Física)'); | |
// Ejemplo de if, else if y else | |
if (clase == 'Genética') { | |
console.log('Tu profesor será Charles Xavier'); | |
} | |
else if (clase == 'Manipulación de Energía') { | |
console.log('Tu profesor será Ciclope'); | |
} | |
else if (clase == 'Educación Física') { | |
console.log('Tu profesor será Bestia'); | |
} | |
else { | |
console.log('Tu elección no es válida'); | |
} | |
// Ejemplo de switch, case, default | |
switch(pokemon) { | |
case 'Bulbasaur': | |
console.log('Bulbasaur es un Pokemon tipo planta'); | |
break; | |
case 'Charmander': | |
console.log('Charmander es un Pokemon tipo fuego'); | |
break; | |
case 'Squirtle': | |
console.log('Squirtle es un Pokemon tipo agua'); | |
break; | |
default: | |
console.log('Tu elección no es válida'); | |
break; | |
} |
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
/* Arreglo de pokemones */ | |
var pokemones = ['Pikachu','Butterfree','Pidgeot','Bulbasaur','Charizard','Squirtle']; | |
// Iterar con while | |
var c = 0; | |
while (c < pokemones.length) { | |
console.log(pokemones[c]); | |
c++; | |
} | |
// Iterar con do while | |
var c = 0; | |
do { | |
console.log(pokemones[c]); | |
c++; | |
} while (c < pokemones.length); | |
// Iterar con for | |
for(var i = 0; i < pokemones.length; i++) { | |
console.log(pokemones[i]); | |
} | |
//Iterar con for in | |
for(var i in pokemones) { | |
console.log(pokemones[i]); | |
} | |
// Iterar con forEach | |
pokemones.forEach(function(x) { | |
console.log(x); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment