Build a Sentence Analyzer - Step 5

Tell us what’s happening:

I can’t figure out why the second console.log doesn’t produce the correct count of 5.

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

const punctuation = ["?","!","'"];
let count = 0;
function getPunctuationCount(sentence){
  for(const char of sentence){
    if(punctuation.includes(char)){
      count++
    }
  }
    return count
}
console.log(getPunctuationCount("What's going on here?"),getPunctuationCount('What????!'))


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15

Challenge Information:

Build a Sentence Analyzer - Step 5

What have you done to investigate?

log all of the variables and expressions in your function to the console.

Hi @dreyes61

For our purposes, a punctuation character is any character that is not a space (" " ) or a letter.

In addition to the advice from @pkdvalis, I think your function needs to be a little more robust.

Happy coding

add a third console.log for getPunctuationCount, how much is the third one distant from the expected value?