Back to Freecodecamp

Step 6

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

latest2.1 KB
Original Source

--description--

Now it is time to test your getPunctuationCount function.

Create a punctuationCount variable and assign it the result of calling the getPunctuationCount function with the argument of "WHAT?!?!?!?!?"

After that, log the following to the console: "Punctuation Count: [Punctuation count goes here]". Replace [Punctuation 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 punctuationCount variable.

js
assert.isNotNull(punctuationCount)

Your punctuationCount variable should be set to the result of getPunctuationCount("WHAT?!?!?!?!?").

js
assert.equal(punctuationCount, getPunctuationCount("WHAT?!?!?!?!?"));

You should log the following to the console: "Punctuation Count: [Punctuation count goes here]". Replace [Punctuation count goes here] with the actual variable name. Make sure to use proper string concatenation syntax here.

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

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

function getPunctuationCount(sentence) {
  const punctuations = ".,!?;:-()[]{}\"'–";
  let count = 0;

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

--fcc-editable-region--

--fcc-editable-region--