Back to Freecodecamp

Step 2

curriculum/challenges/english/blocks/workshop-sentence-analyzer/66e2df8c5676fe51cead8ec8.md

latest1.3 KB
Original Source

--description--

Now it is time to test your getVowelCount function.

Create a vowelCount variable and assign it the result of calling the getVowelCount function with the argument of "Apples are tasty fruits"

After that, log the following to the console: "Vowel Count: [vowel count goes here]". Replace [vowel count goes here] with the actual variable name. You can choose to use template strings or string concatenation with the + operator here.

--hints--

You should create a vowelCount variable.

js
assert.isNotNull(vowelCount)

Your vowelCount variable should be set to the result of getVowelCount("Apples are tasty fruits").

js
assert.equal(vowelCount, getVowelCount("Apples are tasty fruits"));

You should log the vowelCount variable to the console with the parameter "Vowel Count: ${vowelCount}".

js
assert.match(code, /console\.log\((?:('|"|`)Vowel\s+Count:\s+('|"|`)\s+\+\s+vowelCount|`Vowel\s+Count:\s+\${vowelCount}`)\);?/)

--seed--

--seed-contents--

js
function getVowelCount(sentence) {
  const vowels = "aeiou";
  let count = 0;

  for (const char of sentence.toLowerCase()) {
    if (vowels.includes(char)) {
      count++;
    }
  }
  return count;
}

--fcc-editable-region--

--fcc-editable-region--