-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (26 loc) · 978 Bytes
/
index.js
File metadata and controls
26 lines (26 loc) · 978 Bytes
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
function analyse() {
var string = document.getElementById("stringinput").value;
var vowels, consonants, digits, spaces, specialCharacters;
var vowel_list = "aeiouAEIOU";
var digit_list = "0123456789";
vowels = consonants = digits = spaces = specialCharacters = 0;
for (i = 0; i < string.length; i++) {
if (vowel_list.indexOf(string[i]) !== -1) {
vowels += 1;
} else if (string[i] <= "z" && string[i] >= "A") {
consonants += 1;
} else if (digit_list.indexOf(string[i]) !== -1) {
digits += 1;
} else if (string[i] == " ") {
spaces += 1;
} else {
specialCharacters += 1;
}
}
console.log(consonants)
document.getElementById("vowels").innerHTML = vowels;
document.getElementById("consonants").innerHTML = consonants;
document.getElementById("digits").innerHTML = digits;
document.getElementById("spaces").innerHTML = spaces;
document.getElementById("specialCharacters").innerHTML = specialCharacters;
}