let wordsToRemove = ['extremely', 'literally', 'actually'];
textWords = text.split(' ')
let refinedWords = textWords.filter(function (word) {
return !wordsToRemove.includes(word)
})
let reallyCount = 0
let basicallyCount = 0
let veryCount = 0
for (i = 0; i < textWords.length; i += 1) {
if (refinedWords[i] == 'really') {
reallyCount += 1}
if (refinedWords[i] == 'basically') {
basicallyCount += 1}
if (refinedWords[i] == 'very' ) {
veryCount +=1}
}
console.log('Really Count : ', reallyCount)
console.log('Basically Count : ', basicallyCount)
console.log( 'Very Count : ', veryCount)
let sentenceCounter = 0
textWords.forEach(word =>{
if(word[word.length - 1] === "." || word[word.length - 1] === "!"){
sentenceCounter += 1
}
});
console.log(sentenceCounter)
The expected count should be 12 but only shows 1.
The sentences counting function has a mistake. Any suggestions on how to fix it? The problem lies in the last forEach loop. Is there an alternative solution to this issue?