ESTRUCTURA DE CONTROL IF...ELSE
if (time<10)
{
x="Good morning";
}
else if (time<20)
{
x="Good day";
}
else
{
x="Good evening";
}
EJEMPLO
ESTRUCTURA DE CONTROL SWITCH
var day=new Date().getDay();
switch (day)
{
case 0:
x="Today it's Sunday";
break;
case 1:
x="Today it's Monday";
break;
case 2:
x="Today it's Tuesday";
break;
case 3:
x="Today it's Wednesday";
break;
case 4:
x="Today it's Thursday";
break;
case 5:
x="Today it's Friday";
break;
case 6:
x="Today it's Saturday";
break;
}
EJEMPLO
ESTRUCTURA DE CONTROL FOR
<!DOCTYPE html>
<html>
<body>
<script>
cars=["BMW","Volvo","Saab","Ford"];
for (var i=0;i<cars.length;i++)
{
document.write(cars[i] + "<br>");
}
</script>
</body>
</html>
EJEMPLO
ESTRUCTURA DE CONTROL WHILE
while (i<5)
{
x=x + "The number is " + i + "<br>";
i++;
}
Ejemplo
ESTRUCTURA DE CONTROL DO...WHILE
do
{
x=x + "The number is " + i + "<br>";
i++;
}
while (i<5);
Ejemplo
ESTRUCTURA DE CONTROL FOR...WHILE
cars=["BMW","Volvo","Saab","Ford"];
var i=0;
for (;cars[i];)
{
document.write(cars[i] + "<br>");
i++;
}
Ejemplo
ESTRUCTURA DE CONTROL ESTADO BREACK
for (i=0;i<10;i++)
{
if (i==3)
{
break;
}
x=x + "The number is " + i + "<br>";
}
EJEMPLO
CONTROL DE ERRORES
try
{
//Run some code here
}
catch(err)
{
//Handle errors here
}
Ejemplo
APRENDER VALIDACIONES
Para aprender validaciones con java script hacer click en el siguiente enlace
Validaciones
No hay comentarios.:
Publicar un comentario