Skip to content

Instantly share code, notes, and snippets.

@Gonzalo2683
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save Gonzalo2683/5ff49a2ee1ffa8e2dde3 to your computer and use it in GitHub Desktop.

Select an option

Save Gonzalo2683/5ff49a2ee1ffa8e2dde3 to your computer and use it in GitHub Desktop.
Practico 4
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="js/prac4.js" type="text/javascript"></script>
</head>
<body>
<div>TODO write content</div>
Invertir Texto: <input type="text" id="textInver" />
<input type="button" id="btnInver" value="Invertir" />
<hr/>
<input type="text" id="txtFrase" /><input type="text" id="txtLetra" />
<input type="button" id="btnMostrar" value="mostrar" />
<hr/>
<input type="text" id="txtVocales" />
<input type="button" id="btnMostrarVocal" value="Cuantas Vocales" />
<hr/>
<input type="text" id="txtToMin" />
<input type="button" id="btnToMIn" value="Convertir" />
<hr/>
<input type="text" id="txtToMay" />
<input type="button" id="btnToMay" value="Convertir" />
<hr/>
<input type="text" id="txtToMayusPrimera" />
<input type="button" id="btnToMayusUno" value="Convertir" />
</body>
</html>
/*
* 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
$('#btnInver').click(invertirTexto);
//2
$('#btnMostrar').click(cantLetras);
//3
$('#btnMostrarVocal').click(contarVocales);
//4
$('#btnToMIn').click(aMinusculas);
//5
$('#btnToMay').click(aMayusculas);
//6
$('#btnToMayusUno').click(aMayuscula);
}
//1
function invertirTexto(){
var textoInvert = $('#textInver').val();
var largoText = textoInvert.length;
var result = "";
for (var i = largoText - 1; i >= 0; i--) {
result += textoInvert[i];
}
alert(result);
}
//2
function cantLetras(){
var texto = $('#txtFrase').val();
var letra = $('#txtLetra').val();
var contar = contarLetras(texto,letra);
alert(contar);
}
function contarLetras(pTexto,pLetra){
var cont=0;
var extencion= pTexto.length;
for (var i = 0; i <= extencion-1; i++) {
if (pTexto[i]===pLetra) {
cont++;
}
}
return cont;
}
//3
function contarVocales(){
var texto = $('#txtVocales').val();
var contar = cuentaVocal(texto);
alert(contar);
}
function cuentaVocal(pTexto){
var cont=0;
var textoLow = pTexto.toLowerCase();
var extencion= pTexto.length;
for (var i = 0; i <= extencion-1; i++) {
if ((textoLow[i]=== 'a') || (textoLow[i]=== 'e') || (textoLow[i]=== 'i') || (textoLow[i]=== 'o') || (textoLow[i]=== 'u') ) {
cont++;
}
}
return cont;
}
//4
function aMinusculas(){
var texto = $('#txtToMin').val();
var res = converToMinus(texto);
alert(res);
}
function converToMinus(pTexto){
var textoLow = pTexto.toLowerCase();
return textoLow;
}
//5
function aMayusculas(){
var texto = $('#txtToMay').val();
var res = converToMayus(texto);
alert(res);
}
function converToMayus(pTexto){
var textoLow = pTexto.toUpperCase();
return textoLow;
}
//6
function aMayuscula(){
var texto = $('#txtToMayusPrimera').val();
var res = converToMayusculaPrimera(texto);
alert(res);
}
function converToMayusculaPrimera(pTexto){
var convertida = pTexto.charAt(0).toUpperCase() + pTexto.slice(1);
return convertida;
}
var cosa = indiceDe('res','dos rres tigres');
alert(cosa);
function indiceDe(pFragmento, pCadena){
var seguir = true;
var indice = -1;
var i = 0;
while( i < pCadena.length - (pFragmento.length - 1) && seguir){
var coincide = true;
var indiceCadena = i;
var n = 0;
while( n < pFragmento.length && coincide ){
if(pFragmento.charAt(n) != pCadena.charAt(indiceCadena)){
coincide = false;
}
indiceCadena ++; n++;
}
if(coincide == true){
indice = indiceCadena - pFragmento.length;
seguir = false;
}
i++;
}
return indice;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment