HackerRank Challenges

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 righ…


This content originally appeared on DEV Community and was authored by Thaísa Vieira

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]); 
    }

}

input:

javascriptloops

my output:

~ no response on stdout ~

expected output:

a
a
i
o
o
j
v
s
c
r
p
t
l
p
s

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?


This content originally appeared on DEV Community and was authored by Thaísa Vieira


Print Share Comment Cite Upload Translate Updates
APA

Thaísa Vieira | Sciencx (2024-06-22T03:00:36+00:00) HackerRank Challenges. Retrieved from https://www.scien.cx/2024/06/22/hackerrank-challenges/

MLA
" » HackerRank Challenges." Thaísa Vieira | Sciencx - Saturday June 22, 2024, https://www.scien.cx/2024/06/22/hackerrank-challenges/
HARVARD
Thaísa Vieira | Sciencx Saturday June 22, 2024 » HackerRank Challenges., viewed ,<https://www.scien.cx/2024/06/22/hackerrank-challenges/>
VANCOUVER
Thaísa Vieira | Sciencx - » HackerRank Challenges. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/22/hackerrank-challenges/
CHICAGO
" » HackerRank Challenges." Thaísa Vieira | Sciencx - Accessed . https://www.scien.cx/2024/06/22/hackerrank-challenges/
IEEE
" » HackerRank Challenges." Thaísa Vieira | Sciencx [Online]. Available: https://www.scien.cx/2024/06/22/hackerrank-challenges/. [Accessed: ]
rf:citation
» HackerRank Challenges | Thaísa Vieira | Sciencx | https://www.scien.cx/2024/06/22/hackerrank-challenges/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.