Mini Linter Project


#1

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…

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

more particularly the word[word.length-1]

How is it checking for the punctuation marks?


#2

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.