-
Notifications
You must be signed in to change notification settings - Fork 23
/
orbucles.html
81 lines (75 loc) · 1.62 KB
/
orbucles.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ejemplo Bucles</title>
<link href="res/css/bootstrap.min.css" rel="stylesheet">
<style>
body{
padding: 2em;
}
.form-control{
display: inline-block;
width: auto;
}
label{
display: block;
}
.result,
.button-container{
margin-top: 1em;
}
</style>
</head>
<body>
<h1>Contador de vocales</h1>
<div class="inputs">
<label for="word">Palabra</label>
<input type="text" id="palabra" class="form-control">
</div>
<div class="button-container">
<button id="count" class="btn btn-primary">contar vocales</button>
</div>
<div class="result">
<h2>Resultados</h2>
<div class="res-a">
A <span id="a-count"></span>
</div>
<div class="res-e">
E <span id="e-count"></span>
</div>
<div class="res-i">
I <span id="i-count"></span>
</div>
<div class="res-o">
O <span id="o-count"></span>
</div>
<div class="res-u">
U <span id="u-count"></span>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var vowels = 'aeiou',
// elementos
$word = $('#palabra'),
$count = $('#count')
function countVowels(){
var word = $word.val(),
res = { a: 0, e:0, i:0, o:0, u:0 },
vowel;
for(var i=0; i<word.length; i++){
vowel = word[i];
if( vowels.indexOf(vowel) != -1 ){
// res[v] = res[v] + 1
++res[vowel];
}
}
for(var key in res){
$('#' + key + '-count').html( res[ key ] )
}
}
$count.on('click', countVowels)
</script>
</body>
</html>