curriculum/challenges/english/blocks/workshop-sentence-analyzer/66e2f06b191e305c00574e4d.md
Finally, count the number of words by creating a getWordCount function with a sentence parameter. The function should return the total number of words in the sentence passed in when it is called.
You should create a getWordCount function.
assert.isFunction(getWordCount);
Your getWordCount function should have a sentence parameter.
assert.match(getWordCount.toString(), /sentence/);
Your getWordCount function should return a number.
assert.isNumber(getWordCount("I love freeCodeCamp"))
When the sentence is "When are you gonna start learning to code?", the getWordCount function should return 8.
assert.strictEqual(getWordCount("When are you gonna start learning to code?"), 8);
When the sentence is "What's going on?", the getWordCount function should return 3.
assert.strictEqual(getWordCount("What's going on?"), 3);
Your word count should be case-insensitive.
assert.strictEqual(getWordCount("freeCodeCamp offers free coding tutorials online"), 6);
assert.strictEqual(getWordCount("You can learn HTML, CSS, JavaScript, and more on freeCodeCamp"), 10);
Your getWordCount function should return the correct word count for any sentence.
assert.strictEqual(getWordCount("freeCodeCamp has a great community of kind people"), 8);
assert.strictEqual(getWordCount("The freeCodeCamp curriculum is constantly updated"), 6);
assert.strictEqual(getWordCount("freeCodeCamp teaches both front-end and back-end development"), 7);
Your getWordCount function should return the correct word count for an empty string, or a string only with spaces.
assert.strictEqual(getWordCount(""), 0);
assert.strictEqual(getWordCount(" "), 0);
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}`);
--fcc-editable-region--
--fcc-editable-region--