HackerRank Challenges

Thaísa Vieira - Jun 22 - - Dev Community

I'm trying other websites to exercises DSA and I started with HackerRank, 10 days of JavaScript. In this journey my focus is to spend the necessary time to think, search and solve the problems, without being so fixed with deliver challenges in the right days.

Also, I'd like some help with a basic problem with loop:
10 Days of JavaScript - Day 2 (In the link you can check the problem and the see the complete code).
The main problem is to complete the vowelsAndConsonants function that print each vowel in on a new line in the same order as it appeared and after do the same thing for consonants too.

What I did was start with an array storing the vowels and separe in two parts, vowels and not vowels.
In the for loop I started a counter that started at zero, was smaller than the size of the string that the user would provide and the step would be i = i + 1. Then I ask console.log to display the string entered by the user within the function conditions according to the for loop.

function vowelsAndConsonants(s) {
    let vowels = ['a', 'e', 'i', 'o','u'];

    for(let i=0; i<s.lenght; i++){
    if(vowels.includes(s[i]))
    console.log(s[i]);
    }


    for(let i=0;i<s.lenght;i++){
    if(!vowels.includes(s[i]))
    console.log(s[i]); 
    }

}
Enter fullscreen mode Exit fullscreen mode

input:

javascriptloops

Enter fullscreen mode Exit fullscreen mode

my output:

~ no response on stdout ~

Enter fullscreen mode Exit fullscreen mode

expected output:

a
a
i
o
o
j
v
s
c
r
p
t
l
p
s
Enter fullscreen mode Exit fullscreen mode

In the exercise itself there is a main function that calls the function vowelsAndConsonants and captures what the user types.
But I'm not understanding what I'm doing wrong for my output don't return anything. Someone can help me?

. . . . . . . . . . . . .