Build a Sentence Analyzer - Step 3

Tell us what’s happening:

I get the proper counts for vowels and consonants for sentences given like “Coding is fun”, and I do use the toLowerCase() function. But I still get the “Your consonant count should be case-insensitive.” message. Thank you :slight_smile:

Your code so far

function getVowelCount(sentence) {
  const vowels = "aeiouy";
  let count = 0;

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

const vowelCount = getVowelCount("Coding is fun");
console.log(`Vowel Count: ${vowelCount}`);


// User Editable Region

function getConsonantCount (sentence){
  const consonants = "bcdfghjklmnpqrstvwxz";
  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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Build a Sentence Analyzer - Step 3

Does your consonants variable contain all of the consonants?

Your question puzzled me and searched further on consonants, found out following, latin based alphabets consider it a consonant, though with dual function as explained in multiple Wiki sources. But, as my mother tongue is Greek, “y” ‘s origin - “ypsilon“ - is a vocal. Anyway, now it’s clear, thank you :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.