I'm trying to complete a HackerRank challenge that involves printing a list of elements of an array starting with all the vowels then all the consonants but I'm having trouble with that.
function vowelsAndConsonants(s) {
var str = s;
var arr = str.split("");
var i;
var vow = ["a","e","i","o","u","y"];
var con = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z']
for (i = 0; i < arr.length; i++) {
for (var j = 0; j< vow.length; j++){
if (arr[i] === vow[j]){
console.log(arr[i])
}
}
}
}
This is what I get from the code above, but I can't print the consonants. The input string is "javascriptloops"
a
a
i
o
o
I also tried this
function vowelsAndConsonants(s) {
var str = s;
var arr = str.split("");
var i;
var vow = ["a","e","i","o","u","y"];
var con = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z']
for (i = 0; i < arr.length; i++) {
for (var j = 0; j< vow.length; j++){
if (arr[i] === vow[j]){
console.log(arr[i])
break;
}
}
for (var j = 0; j< con.length; j++){
if (arr[i] === con[j]){
console.log(arr[i])
}
}
}
}
But here's what I had
j
a
v
a
s
c
r
i
p
t
l
o
o
p
s