Build a Sentence Analyzer - Step 1

Tell us what’s happening:

Hello!

My function definetely works as required:

  1. Returns a number;
  2. Returns 7 when the sentence is “Apples are tasty fruits”;
  3. Returns 3 when the sentence is “Hello, World!”;
  4. Works with both lower- and uppercase letters in the sentence.

However, the FCC code editor gives me this error: Your getVowelCount function should return a number.

I believe it’s a bug?

Your code so far


// User Editable Region

const getVowelCount = (sentence) => {
    sentence = sentence.toLowerCase();

    const vowels = ['a', 'e', 'i', 'o', 'u'];
    let vowelsCount = 0;

    for (char of sentence) {
        if (vowels.includes(char)) vowelsCount++;
    }

    return vowelsCount;
}

// 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

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

Welcome to the forum @LetMeFork!

Yes; your code has a bug.

If I test your function like this: console.log(getVowelCount("The quick brown fox jumped over the whatever"))

I see this in the console:

ReferenceError: char is not defined

Happy coding!

Riiiight, I forgot to declare the char variable in the for…of loop :grinning_face:

Nonetheless, before fixing the loop, the function did return 13 to my console when I checked your sentence.

Thank you for the hint!

Congratulations on solving the challenge! You should be proud of your achievement…we are! But we are removing your working solution, so it is not available to others who have not yet done the work to get there. Again, congrats!

where you testing in the browser console? the browser console does not run in strict mode by default

Correct, and that’s why I didn’t get any errors in the console when running my previous code with the syntax problem.
Putting the “use strict”; directive at the beginning of the .js file fixed the issue. Before that, I didn’t know about “sloppy” and strict modes