-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountVowels.js
41 lines (41 loc) · 948 Bytes
/
countVowels.js
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
function capitalise(word){
let str=word
let strCopy=""
let difference="a".charCodeAt(0)-"A".charCodeAt(0)
for (let i=0; i<str.length; i++){
if (str[i]>="a" && str[i]<="z"){
strCopy+=String.fromCharCode(str[i].charCodeAt(0)-difference)
}
else{
strCopy+=str[i]
}
}
return strCopy
}
function isVowel(letter){
if (letter==="A" || letter==="E" || letter==="I" || letter==="O" || letter==="U"){
return true
}
else{
return false
}
}
function countVowels(word) {
// let modifiedWords=word.toUpperCase()
// let count=0
// let vowels=["A", "E", "I", "O", "U"]
// for (let i=0; i<=modifiedWords.length; i++){
// if (vowels.includes(modifiedWords[i])){
// count=count+1
// }
// }
// return count
let capitalisedWord=capitalise(word)
let count=0
for (let i=0; i<word.length; i++){
if (isVowel(capitalisedWord[i])){
count+=1
}
}
return count
}