-
Notifications
You must be signed in to change notification settings - Fork 1
/
CE3.js
36 lines (28 loc) · 919 Bytes
/
CE3.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
let inputsSentence = 'Selamat Pagi Duniaa';
let inputVowels = ['a', 'i', 'u', 'e', 'o'];
let hitung = 0;
function countVowels(str, vowels) {
for (let i = 0; i < str.length; i++) {
for (let j = 0; j < inputVowels.length; j++) {
if (str[i] === inputVowels[j]) {
hitung++
}
}
}
}
countVowels(inputsSentence, inputVowels);
console.log(`Output: ${hitung}`);
// =====================================================================
function manipulateString(str) {
let stringSpasi = "";
for (let i = 0; i < str.length; i++) {
if (i > 0 && str[i].toUpperCase() === str[i]){
stringSpasi += " ";
}
stringSpasi += str[i];
}
return stringSpasi;
}
inputString = 'SelamatPagiSemua';
let stringSpasi = manipulateString(inputString);
console.log(`Output: ${stringSpasi}`);