El siguiente programa está destinado al uso de vectores dentro de javascript así como de aplicar distintos métodos para la validación de diferentes tipos de datos.
Código:
<html>
<head>
<title>Ejercicios de vectores</title>
<script language="javascript" type="text/javascript">
// VECTORES CON ENTRADAS DE DATOS
var telefono = new Array(10);
var usuario = new Array(10);
var ph = new Array(10);
for (var i=0; i<10; i++)
{
telefono[i] = ""; // Ingreso y validación de teléfono
while (telefono[i].length != 10)
{
telefono[i] = prompt("Teléfono:");
}
usuario[i] = ""; // Ingreso y validación de usuario
while (usuario[i] == "")
{
usuario[i] = prompt("Ingresa Usuario:");
}
ph[i] = 0; // Ingreso y validación
while (ph[i] <= 0)
{
ph[i] = prompt("Ingresa valor de pH:");
ph[i] = parseFloat(ph[i]);
}
}
for (var i=0; i<10; i++)
{
document.write("Teléfono: " + telefono[i] + "<br>");
document.write("Usuario: " + usuario[i] + "<br>");
document.write("pH: " + ph[i] + "<br><br>");
}
</script>
</head>
<body>
document.write("Usuario no existente <br>");
</body>
</html>
No hay comentarios:
Publicar un comentario