Build a Sentence Analyzer - Step 5

Tell us what’s happening:

I have tried with the sentences it tests against and get the correct punctuation count. But can not figure out why it is failing even though it gives the correct count. I could have included every punctuation but given I knew it was testing for ?! and ’ i just used those.

Your code so far

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


// User Editable Region

function getPunctuationCount (sentence) {
  const punc = "!?'";
  let count = 0;
 for (const char of sentence.toLowerCase()) {
    if (punc.includes(char)) {
      count++;
    }
  }
  return count;
}
const PunctuationCount  = getPunctuationCount ("testing!!!!?");
console.log(`punc Count: ${PunctuationCount}`);
 

// 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/140.0.0.0 Safari/537.36

Challenge Information:

Build a Sentence Analyzer - Step 5
https://www.freecodecamp.org/learn/full-stack-developer/workshop-sentence-analyzer/step-5

try this one

console.log(getPunctuationCount("freeCodeCamp, again? It's incredible!"));
1 Like