CURSO BASICO DE PROGRAMACION CLASE 1
Enviado por Yolibeth Ch • 9 de Julio de 2016 • Tutorial • 278 Palabras (2 Páginas) • 149 Visitas
CURSO BASICO DE PROGRAMACION
CLASE 1
APRENDIENDO ALGORITMOS
VARIABLES, FUNCIONES Y CICLOS
EJEMPLO 1
var turno = 1;
var pikachu = {
vida : 100,
ataque : 55,
win : function(){
console.log('¡pikachu ha ganado!')
}
}
var jigglypuff = {
vida : 100,
ataque : 45,
win : function(){
console.log('jigglypuff ha ganado!')
}
}
while(pikachu.vida > 0 && jigglypuff.vida > 0){
if(turno == 1){
jigglypuff.vida = jigglypuff.vida - pikachu.ataque;
turno = 2;
console.log('jigglypuff ahora tiene '+jigglypuff.vida+' puntos de vida');
}else{
pikachu.vida = pikachu.vida - jigglypuff.ataque;
turno = 1;
console.log('pikachu ahora tiene '+pikachu.vida+' puntos de vida');
}
}
if(pikachu.vida >= 0){
pikachu.win();
}else{
jigglypuff.win();
}
CLASE 2
CONDICIONALES Y OPERADORES EN PROGRAMACIÓN
var perro = {
fuerza: 100,
peso: 18,
tipo: "aventurero",
agilidad: 65,
higiene: false,
amor: true,
edad: 2,
salud: "vacunado",
nombre: "pablo"
};
var gato = {
fuerza: 40,
peso: 4,
tipo: "casero",
agilidad: 40,
higiene: true,
amor: false,
edad: 0,
salud: "inmune",
nombre: "elena"
};
var mascota = gato;
var puntos = 0;
if(mascota.fuerza > 90){
puntos++;
}
if(mascota.peso > 10){
puntos++;
}
if(mascota.tipo == "aventurero"){
puntos = puntos + 2;
}
if(mascota.agilidad >= 70){
puntos++;
}
if(mascota.higiene != true){
puntos++;
}
if(mascota.amor == true){
puntos++;
}
if(mascota.edad > 1 && mascota.edad < 4){
puntos += 2;
}
else if(mascota.edad == 0){
puntos++;
}else
{
puntos--;
}
if(mascota.salud == "vacunado" || mascota.salud == "inmune"){
puntos++;
}
alert("Tu mascota " + mascota.nombre + " tiene "+ puntos);
...