Back to Freecodecamp

Step 3

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

latest2.0 KB
Original Source

--description--

It's time to count the consonants. Create a getConsonantCount function with a sentence parameter.

Inside the function, use a loop to count the number of consonants in the sentence that will be passed into the function when it is called. A consonant is any letter that is not one of the following characters: "aeiou".

Your getConsonantCount function must return a number.

--hints--

You should create a getConsonantCount function.

js
assert.isFunction(getConsonantCount);

Your getConsonantCount function should have a sentence parameter.

js
assert.match(getConsonantCount.toString(), /sentence/);

Your getConsonantCount function should return a number.

js
assert.isNumber(getConsonantCount("Coding is fun"))

When the sentence is "Coding is fun", the getConsonantCount function should return 7.

js
assert.strictEqual(getConsonantCount("Coding is fun"), 7);

When the sentence is "Hello, World!", the getConsonantCount function should return 7.

js
assert.strictEqual(getConsonantCount("Hello, World!"), 7);

Your consonant count should be case-insensitive.

js
assert.strictEqual(getConsonantCount("Apples are tasty fruits"), 13);
assert.strictEqual(getConsonantCount("freeCodeCamp is awesome"), 11);

Your getConsonantCount function should return the correct consonant count for any sentence.

js
assert.strictEqual(getConsonantCount("I went to the store"), 9);
assert.strictEqual(getConsonantCount("The quick brown fox jumps over the lazy dog"), 24);
assert.strictEqual(getConsonantCount("The cat in the hat"), 9);
assert.strictEqual(getConsonantCount(""), 0);

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

const vowelCount = getVowelCount("Apples are tasty fruits");
console.log(`Vowel Count: ${vowelCount}`);

--fcc-editable-region--

--fcc-editable-region--