Created
May 26, 2015 01:26
-
-
Save Gonzalo2683/cb7e2032c6ce00492cc3 to your computer and use it in GitHub Desktop.
Practico 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>TODO supply a title</title> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <link rel="stylesheet" href="css/estilos.css"/> | |
| <script src="js/jquery-1.11.3.min.js"></script> | |
| <script src="js/practico6.js"></script> | |
| </head> | |
| <body> | |
| <div class="contenedor"> | |
| <h2>1</h2> | |
| Ingresar Alias:<input type="text" id="textAlias" /> | |
| <input id="btnAlias" type="button" value="Ingresar Alias" /> | |
| <input id="btnMostrarAlias" type="button" value="Mostrar Alias" /> | |
| <div class="divAlias"></div> | |
| <hr /> | |
| <h2>2</h2> | |
| <input id="btnLargo" type="button" value="Mostrar Largo" /> | |
| <hr /> | |
| <h2>3</h2> | |
| <input id="btnMasGrande" type="button" value="Mostrar mayor" /> | |
| <h2>4</h2> | |
| Ingresar palabras:<input type="text" id="textPalabras" /> | |
| <input id="btnPal" type="button" value="Ingresar Palabra" /> | |
| <input id="btnMostrarPal" type="button" value="Mostrar Palabras" /> | |
| <div class="divPalabras"></div> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * To change this license header, choose License Headers in Project Properties. | |
| * To change this template file, choose Tools | Templates | |
| * and open the template in the editor. | |
| */ | |
| $(document).ready(inicio); | |
| function inicio(){ | |
| //1 | |
| $('#btnAlias').click(agregarAlias); | |
| $('#btnMostrarAlias').click(mostrarAlias); | |
| //2 | |
| $('#btnLargo').click(mostrarLargo); | |
| //3 | |
| $('#btnMasGrande').click(elNumMayor); | |
| //4 | |
| $('#btnPal').click(ingPalabra); | |
| $('#btnMostrarPal').click(mostrarPalabras); | |
| //5 | |
| promedio(); | |
| $('#textAlias').val('Hola mundo||||'); | |
| } | |
| //1 | |
| var alias = ['pepe','tino', 'charles', 'alaska', 'triton']; | |
| var nombres = ['pepe','tino', 'charles', 'alaska', 'triton']; | |
| var valores = [4, 12, 2, 6, 12 ]; | |
| function agregarAlias(){ | |
| var textAlias = $('#textAlias').val(); | |
| if(textAlias !== ''){ | |
| var exiteElAlias = existeAlias(textAlias); | |
| if(!exiteElAlias){ | |
| alias.push(textAlias); | |
| }else { | |
| alert('Este alias ya existe'); | |
| } | |
| }else { | |
| alert('El campo esta vacío'); | |
| } | |
| } | |
| function existeAlias(aliasText){ | |
| var existeAlias = false; | |
| var i = 0; | |
| while( i < alias.length && existeAlias === false){ | |
| if((aliasText === alias[i])){ | |
| existeAlias = true; | |
| } | |
| i++; | |
| } | |
| return existeAlias; | |
| } | |
| function mostrarAlias(){ | |
| var divAlias = $('.divAlias'); | |
| var result = ""; | |
| for (var i = 0; i < alias.length ; i++) { | |
| result += alias[i] + '<br />'; | |
| } | |
| divAlias.html(result); | |
| } | |
| //2 | |
| function mostrarLargo(){ | |
| var nuevoArray = []; | |
| var largoIndice = 0; | |
| for (var i = 0; i < alias.length; i++) { | |
| largoIndice = alias[i].length; | |
| nuevoArray.push(largoIndice); | |
| } | |
| alert(nuevoArray); | |
| } | |
| //3 | |
| function elNumMayor(){ | |
| var numeroMayor = 0; | |
| for (var i = 0; i < valores.length; i++) { | |
| if(numeroMayor < valores[i]){ | |
| numeroMayor = valores[i]; | |
| } | |
| } | |
| alert(numeroMayor); | |
| } | |
| var vecPalabras=[]; | |
| function ingPalabra(){ | |
| var palabra=$("#textPalabras").val(); | |
| if (palabra!="") { | |
| vecPalabras.push(palabra); | |
| }else { | |
| alert("campo vacio"); | |
| } | |
| } | |
| function mostrarPalabras(){ | |
| var res=""; | |
| for (var i =0; i < vecPalabras.length; i++) { | |
| res+= vecPalabras[i] + "<br/>"; | |
| } | |
| $(".divPalabras").html(res); | |
| } | |
| //alert(Number.MIN_VALUE); | |
| //alert(Number.MAX_VALUE); | |
| function promedio(){ | |
| var res=0; | |
| for (var i = 0; i < valores.length; i++) { | |
| res+= valores[i]; | |
| } | |
| var resultado= res / valores.length; | |
| alert('El resultado es: ' +'res= '+ res + '/' + valores.length + ' Res= ' + resultado); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment