2 questions

Here is my code for the mini linter project. My first question is, in the sentences counter section, why does using word[word.length-1] === ‘.’ work however if I change this to word[word[0]] === ‘.’ the code no longer works. Why is this the case? Both methods should lead to the same result because I am checking if the character at index 0 of each word is ‘.’.
My other question is: 1. For the overused words, remove it every other time it appears. I tried to do this within my for of loop however it doesn’t actually remove these words from the array. How would I reformat my code to achieve this?

let story = ‘Last weekend, I took literally the most beautiful bike ride of my life. The route is called “The 9W to Nyack” and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey. It’s really an adventure from beginning to end! It is a 48 mile loop and it basically took me an entire day. I stopped at Riverbank State Park to take some extremely artsy photos. It was a short stop, though, because I had a really long way left to go. After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey. The GW is actually very long - 4,760 feet! I was already very tired by the time I got to the other side. An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson. Something that was very surprising to me was that near the end of the route you actually cross back into New York! At this point, you are very close to the end.’;

let overusedWords = [‘really’, ‘very’, ‘basically’];

let unnecessaryWords = [‘extremely’, ‘literally’, ‘actually’ ];

let storyWords = story.split(" ")
//console.log(storyWords.length)
let reallyCount = 0
let veryCount = 0
let basicallyCount = 0

let betterWords = storyWords.filter(function(word) {
return !unnecessaryWords.includes(word)
}
)
console.log(betterWords.length)
for (word of betterWords) {
if (word === ‘really’) {
reallyCount++
if (reallyCount % 2 != 0) {
delete betterWords[word]
}
} else if (word === ‘very’) {
veryCount++
if (veryCount % 2 != 0) {
delete betterWords[word]
}
} else if (word === ‘basically’) {
basicallyCount++
if (basicallyCount % 2 != 0) {
delete betterWords[word]
}
}
}
let sentences = 0;
betterWords.forEach(word => {
if (word[word.length-1] === ‘.’ || word[word.length-1] === ‘!’) {
sentences+=1;
}
});
console.log(sentences)

const logFunction = () =>
console.log('The word count is ’ + storyWords.length + '. The sentence count is ’ + sentences + '. The number of times you used the word really was ’ + reallyCount + ', the number of times you used the word very was ’ + veryCount + ', and the number of times you used the word basically was ’ + basicallyCount)

//console.log(logFunction())
//console.log(betterWords.join(" "))
console.log(storyWords.length)
console.log(betterWords.length)

The above index polls the last character in the word, not the first character. word[0] is the first character. Full stops, question marks, exclamation marks, commas, colons and semi-colons will appear at the end of the word.

To your second question, consider the methodology of first creating an index of all the locations of the overused word, then iterate over every second item in the index.

Hey @jacobkearns892582326, have you had a chance to read the help resources? They include some good tips on things like how to format your code here on the forums so people can read it properly.

Good luck :slight_smile: