-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_loops.js
29 lines (27 loc) · 943 Bytes
/
07_loops.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
/**
* Task
* Complete the vowelsAndConsonants function in the editor below.
* It has one parameter, a string, s, consisting of lowercase English alphabetic letters (i.e., a through z).
* The function must do the following:
1. First, print each vowel in s on a new line.
The English vowels are a, e, i, o, and u, and each vowel must be printed in the same order as it appeared in s.
2. Second, print each consonant (i.e., non-vowel) in on a new line in the same order as it appeared in s.
*/
function vowelsAndConsonants(s) {
let vowels = "";
let consonants = "";
let result = "";
for(var i=0;i<s.length;i++){
if(s[i]=='a'|| s[i]=='i'||s[i]=='e'||s[i]=='o'||s[i]=='u'){
vowels += s[i];
}
else{
consonants += s[i];
}
}
result = vowels+consonants;
for(var j=0;j< result.length;j++){
console.log(result[j])
}
}
vowelsAndConsonants('javascriptloops');