I am trying to count the number of sentences in an array using the .forEach iterator on an array. Each time there is a full stop ('.') or an exclamation mark ('!'), it should increment a counter by 1. I was wondering if it was possible to do this using a Javascript iterator.
The array I am filtering through is called betterWords.
The code below returns 0 for some reason and I'm not sure why.
let sentences = 0;
betterWords.forEach(word => {
if (word === '.' || word === '!') {
return sentences+=1
}
});
console.log(sentences)
betterWords?.or!