Build a Sentence Analyzer - Step 7

Tell us what’s happening:

I’m gettin 6 and 2 as the world counts. How do I get to 8 and 3?

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

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

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

const punctuationCount = getPunctuationCount("WHAT?!?!?!?!?");
console.log(`Punctuation Count: ${punctuationCount}`);


// User Editable Region

function getWordCount(sentence){
  let count = 0;
  for(let char of sentence.toLowerCase()){
    if(char == " "){
      count++
    }
  }
  return count 
}
console.log(getWordCount("When are you gonna learn to code?"))
console.log(getWordCount("What's going on?"))

// 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 7

  • what does this conditional checks?
  • as in what is value of “char” in each iteration?
  • what are you counting here?
  • and what does that entails?

happy coding :slight_smile: