miércoles, 27 de mayo de 2015

Soluciones ejercicios de JavaScript.

Ejercico 1 .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Calculo de la letra del DNI</title>
<script type="text/javascript">
var letras = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'];
var letras2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
var i;
var x;
var resul;
for(i in letras2)
{
    for(x in letras)
        {
              if(letras2[i]==letras[x])
            {
              resul += 1;
              }
        }
        if (resul == 0)
        {
           alert(letras2[i]);
           }
        resul=0;
}
</script>
</head>
<body>
<p>ok</p>
</body>
</html>
Ejercicio 2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ejercicio 2</title>
 <script type="text/javascript">
function alreves(cadena) {
  var cadenaarray = cadena.split(" "); 
 var cadenareves=cadenaarray.reverse();
 var cadenafin=cadenareves.join(" ");
    return cadenafin;
}
 var mensaje=prompt("Introcuce tu nombre y dos apellidos");
alert(alreves(mensaje));
</script>
</head>
 <body>
<p> HOLA</p>
</body>
</html>
Ejercicio 5.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>numero de caracteres</title>
 <script type="text/javascript">
var texto="5.    Realizar un ejercicio que cuando se pulse en el enunciado nos muestre el número de caracteres."
var numero = texto.length;
</script>
</head>
 <body>
<p onclick="alert(numero)">5.    Realizar un ejercicio que cuando se pulse en el enunciado nos muestre el número de caracteres.</p>
</body>
</html>
Ejercicio 6.
 !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>mayor</title>
 <script type="text/javascript">
var numeros = prompt("Introduce los números ");
var numero=0;
numero = numeros.split(" ");
var mayor=0;
for(var i = 0; i <=numero.length; i++)
{
     if (numero[i] >= mayor)
     {
        mayor= numero[i];
     }
}
alert(mayor);
</script>
</head>
 <body>
ok
</body>
</html>
Ejercicio 7.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>posicion</title>
 <script type="text/javascript">
var numeros = prompt("Introduce los números ");
var numero=0;
numero = numeros.split(" ");
var mayor=0;
for(var i = 0; i <=numero.length-1; i++)
{
     if (numero[i] >= mayor)
     {
        mayor= numero[i];
     }
}
var posicion = numero.indexOf(mayor);
alert(posicion);
</script>
</head>
 <body>
ok
</body>
</html>

No hay comentarios:

Publicar un comentario