<html> <body> Dividiendo numeros con do-while... <script> var n1 = prompt("Dime un primer numero"); var n2; do { n2 = prompt("Dime el segundo numero (no debe ser cero)"); } while (n2 == 0); document.write(n1 + " dividido entre "+ n2 + " es: "); var resultado = parseInt(n1) / parseInt(n2); document.write(resultado); </script> </body> </html>
Mostrando entradas con la etiqueta do while. Mostrar todas las entradas
Mostrando entradas con la etiqueta do while. Mostrar todas las entradas
sábado, 25 de marzo de 2017
Dividir entre 2
miércoles, 15 de marzo de 2017
Bucle para imprimir números naturales
<html>
<head>
<title>Practica7</title>
<script type="text/javascript">
//Imprimir los 10 primeros numeros naturales
var x, y;
//Con ciclo for
document.write("Imprime los numeros naturales del 1 al 10 <br>");
for (x = 1; x <= 10; x++)
{
document.write( x + "; ");
}
document.write("<br>");
//solo los pares
document.write("Imprime los numeros naturales pares del 1 al 10 <br>");
for (x = 1; x < 10; x++)
{
if (x % 2)
{
x++;
}
document.write( x + '; ');
}
document.write("<br>");
//Bucle anidado
document.write("Imprime una tabla de los numeros naturales del 1-10 <br>");
for (x = 1; x < 10; x++)
{ for (y = 1; y < 10; y++)
{
document.write(x + ":" + y+" ");
}
document.write('<br>');
}
document.write("<br>");
//Bucle infinito
document.write("Imprime los numeros naturales del 1-10 utilizando un bucle infinito <br>");
x=1;
for (;;)
{
document.write( x + '; ');
x++;
if(x==10)
break;
}
document.write("<br>");
//Bucle while
document.write("Imprime los numeros naturales del 1-10 utilizando un bucle while <br>");
var x = 1;
while (x < 10)
{
document.write( x + "; ");
x++;
}
document.write("<br>");
//Bucle while
document.write("Imprime los numeros naturales del 1-10 utilizando un bucle while <br>");
var x = 1;
do
{
document.write( + x + "; ");
x++;
} while (x < 10);
document.write("<br>");
//Aplicación: Trabajando con listas
document.write("Imprime una lista utilizando bucle for <br>");
var lista = ["1primero","2segundo","3tercero"];
for (i=0; i<lista.length; i++)
{
document.write(lista[i]+"; ");
}
document.write("<br>");
</script>
</head>
<body>
</body>
</html>
<head>
<title>Practica7</title>
<script type="text/javascript">
//Imprimir los 10 primeros numeros naturales
var x, y;
//Con ciclo for
document.write("Imprime los numeros naturales del 1 al 10 <br>");
for (x = 1; x <= 10; x++)
{
document.write( x + "; ");
}
document.write("<br>");
//solo los pares
document.write("Imprime los numeros naturales pares del 1 al 10 <br>");
for (x = 1; x < 10; x++)
{
if (x % 2)
{
x++;
}
document.write( x + '; ');
}
document.write("<br>");
//Bucle anidado
document.write("Imprime una tabla de los numeros naturales del 1-10 <br>");
for (x = 1; x < 10; x++)
{ for (y = 1; y < 10; y++)
{
document.write(x + ":" + y+" ");
}
document.write('<br>');
}
document.write("<br>");
//Bucle infinito
document.write("Imprime los numeros naturales del 1-10 utilizando un bucle infinito <br>");
x=1;
for (;;)
{
document.write( x + '; ');
x++;
if(x==10)
break;
}
document.write("<br>");
//Bucle while
document.write("Imprime los numeros naturales del 1-10 utilizando un bucle while <br>");
var x = 1;
while (x < 10)
{
document.write( x + "; ");
x++;
}
document.write("<br>");
//Bucle while
document.write("Imprime los numeros naturales del 1-10 utilizando un bucle while <br>");
var x = 1;
do
{
document.write( + x + "; ");
x++;
} while (x < 10);
document.write("<br>");
//Aplicación: Trabajando con listas
document.write("Imprime una lista utilizando bucle for <br>");
var lista = ["1primero","2segundo","3tercero"];
for (i=0; i<lista.length; i++)
{
document.write(lista[i]+"; ");
}
document.write("<br>");
</script>
</head>
<body>
</body>
</html>
Suscribirse a:
Entradas (Atom)