-
Notifications
You must be signed in to change notification settings - Fork 23
/
ciclos.html
66 lines (60 loc) · 1.45 KB
/
ciclos.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Contador de Vocales</title>
</head>
<body>
<h1>Contador de Vocales</h1>
<label for="frase">Ingresa tu frase:</label>
<input type="text" id="frase">
<button id="contar">contar vocales</button>
<div class="resultados">
<div class="res">
A <span id="a-vocal"></span>
</div>
<div class="res">
E <span id="e-vocal"></span>
</div>
<div class="res">
I <span id="i-vocal"></span>
</div>
<div class="res">
O <span id="o-vocal"></span>
</div>
<div class="res">
U <span id="u-vocal"></span>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var $frase = $('#frase'),
$contar = $('#contar'),
vocales = 'aeiou';
$frase.on('keyup', function( evt ){
if( evt.keyCode == '13' ){
contarVocales()
}
})
$contar.on('click', contarVocales)
function contarVocales(){
// var frase = $frase.val(),
var frase = $frase.val().toLowerCase(),
res = {a:0, e:0, i:0, o:0, u:0},
letra;
for(var i=0; i<frase.length; ++i){
letra = frase[i];
if( vocales.indexOf( letra ) != -1 ){
// res[letra] = res[letra] + 1;
// res[letra] += 1;
res[letra]++;
}
}
for( var key in res ){
console.log( key, res[ key ], $('#' + key + '-vocal') )
$('#' + key + '-vocal').text( res[ key ] )
}
}
</script>
</body>
</html>