Build a Sentence Analyzer - Step 1

Tell us what’s happening:

I’m on step 1 but failing tests 4 to 7.
There’s also no output to the console.
I can’t really tell what is wrong.
Any help would be appreciated

Your code so far

// User Editable Region
function getVowelCount(sentence){
   let vowelCount = 0
   let vowelArray = ["a","e", "i","o","u"]
   let vowelArray2 = ["A","E","I","O","U"]
   for(const letter of sentence){
    if(vowelArray.includes(letter) || vowelArray2.includes(letter)){
      vowelCount++
    }
    return vowelCount
   }

   console.log(getVowelCount("Hello, World!"))




  
}
// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0

Challenge Information:

Build a Sentence Analyzer - Step 1

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-sentence-analyzer/66e2d680e129e1423116a541.md at main · freeCodeCamp/freeCodeCamp · GitHub

hello!

should the console.log statement be inside the getVowelCount function?

should the return vowelCount statement be inside the for...of loop block?

There are two mistakes in your code.

First, you placed return vowelCount inside the for loop. As a result, the function returns after checking only the first character of the string instead of processing the entire sentence.

Second, you placed console.log(getVowelCount("Hello, World!")) inside the getVowelCount function. The console.log statement should be outside the function so that it can call the function and display the result after the function has been defined.

I think you may have misunderstood JavaScript scope.