Mini Linter Project


I’ve reached the sentence count question and got the code to run successfully, with the help of a hint. I’m just not understanding how it works properly…

let sentenceCount = 0;
betterWords.forEach(word => {
if (word[word.length-1] === ‘.’ ||
word[word.length-1] === ‘!’) {

more particularly the word[word.length-1]

How is it checking for the punctuation marks?


word.length - 1 is the index of the last character in the string. If it is a period (full stop) or an exclamation mark then 1 is added to the count.