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