Back to Freecodecamp

Step 5

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

latest2.3 KB
Original Source

--description--

You should count the number of punctuations now.

Create a getPunctuationCount function with a sentence parameter.

Inside the function, create a loop to count the number of punctuation characters in the sentence that will be passed into the function when it is called. For our purposes, a punctuation character is any character that is not a space (" ") or a letter.

Your getPunctuationCount function must return a number.

--hints--

You should create a getPunctuationCount function.

js
assert.isFunction(getPunctuationCount);

Your getPunctuationCount function should have a sentence parameter.

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

Your getPunctuationCount function should return a number.

js
assert.isNumber(getPunctuationCount("Coding is fun!"))

When the sentence is "What's going on here?", the getPunctuationCount function should return 2.

js
assert.strictEqual(getPunctuationCount("What's going on here?"), 2);

When the sentence is "What????!", the getPunctuationCount function should return 5.

js
assert.strictEqual(getPunctuationCount("What????!"), 5);

Your getPunctuationCount function should return the correct punctuation count for any sentence.

js
assert.strictEqual(getPunctuationCount("Be quick, sign up! freeCodeCamp awaits, friend!!!"), 6);
assert.strictEqual(getPunctuationCount("Guess what? freeCodeCamp is launching a new cert soon!"), 2);
assert.strictEqual(getPunctuationCount("freeCodeCamp, again? It's incredible!"), 4);
assert.strictEqual(getPunctuationCount(""), 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}`);

function getConsonantCount(sentence) {
  const consonants = "bcdfghjklmnpqrstvwxyz";
  let count = 0;

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

const consonantCount = getConsonantCount("Coding is fun");
console.log(`Consonant Count: ${consonantCount}`);

--fcc-editable-region--

--fcc-editable-region--