-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordPlay.js
45 lines (37 loc) · 1.22 KB
/
wordPlay.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
42
43
44
45
let word = "salve"
let variableLength = word.length
let empty = ""
function inverseWord(wordToInverte, invertedWord) {
for(let i = variableLength - 1; i >= 0 ; i--) {
invertedWord += wordToInverte[i]
}
return invertedWord
}
let invertedResult = inverseWord(word, empty)
console.log(`The inverted form of the word "${word}" is "${invertedResult}".`)
function countNumberVowels(wordToCount) {
let count = 0
for(let i = 0; i < variableLength; i++) {
if (wordToCount[i] == 'a' || wordToCount[i] == 'e' || wordToCount[i] == 'i' || wordToCount[i] == 'o' || wordToCount[i] == 'u'){
count++
} else if (wordToCount[i] == 'A' || wordToCount[i] == 'E' || wordToCount[i] == 'I' || wordToCount[i] == 'O' || wordToCount[i] == 'U') {
count++
}
}
return count
}
let countVowels = countNumberVowels(word)
console.log(`The word "${word}" has ${countVowels} vowels.`)
function makeReport(word) {
if (typeof word != "string") {
console.log("oh carai")
return undefined
}
const report = {
word: `${word}`,
invertedWord: inverseWord(word, empty),
numberOfVowels: countNumberVowels(word)
}
return report
}
console.log(makeReport(word))