Tell us what’s happening:
i dont know why its not working n saying Your getWordCount function should return the correct word count for an empty string, or a string only with spaces.
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
const getWordCount = (sentence) =>
{
let count = 0;
if (sentence === '')
{
count = 0;
}
else{
count = 1;
}
let spaces = ' ';
for (const words of sentence)
{
if(spaces.includes(words))
{
count++;
}
}
return count
}
console.log(getWordCount("When are you gonna start learning to code?"))
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:153.0) Gecko/20100101 Firefox/153.0
Challenge Information:
Build a Sentence Analyzer - Step 7