Mini Linter

https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/learn-javascript-iterators/projects/mini-linter

I need help. I’ve been stuck on the 4th point of the project

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 unnecessaryWords = [‘extremely’, ‘literally’, ‘actually’ ];

let storyWords = story.split(’ ');
console.log(storyWords);

// let betterWords = storyWords.filter(word => {
// if (word !== ‘extremely’ || word !== ‘literally’ || word !== ‘actually’) {
// return word;
// }
// })

// let betterWords = storyWords.filter(word => {
// if (word !== unnecessaryWords.includes(word)) {
// return word;
// }
// })

// console.log(storyWords);

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

let reallyCount = 0;
let veryCount = 0;
let basicallyCount = 0;

for (word in storyWords) {
** if (word === ‘really’) {**
** reallyCount += 1;**
** } else if (word === ‘very’) {**
** veryCount += 1;**
** } else if (word === ‘basically’) {**
** basicallyCount += 1;**
** }**
}

console.log('My Really count is: ’ + reallyCount)

I’m pretty sure I wrote the code correctly, but when I console.log it shows 0 to all three variables. I’m lost.

You could use console.log to write out the results of your comparisons. And if the outcome isn’t what you expect you could look at what values you are comparing.

Don’t just state that the variables are zero at the end. Go look at what you did leading up to that.
For each operation that you rely on, you can write out what inputs and outputs you’re using and then afterwards you can write out what the result was, allowing you to observe individual operations.

//step 1
let storyWords = story.split(’ ');
//step 2
console.log(storyWords.length);
//step 3
let betterWords = storyWords.filter(function(word) {
return !unnecessaryWords.includes(word)
})
//step 4
let reallyCount = 0;
let veryCount = 0;
let basicallyCount = 0;
for (word in storyWords) {
if (word === ‘really’) {
reallyCount += 1;
} else if (word === ‘very’) {
veryCount += 1;
} else if (word === ‘basically’) {
basicallyCount += 1;
}
}
console.log(basicallyCount)

I tried this way and that way, again and again. Not working :frowning: I even watched step by step video. The count of overusedWords are showing 0 no matter what. I am at a total loss.

Sounds to me like you’re still doing the same thing. Not observing the actions your code is carrying out.
You treat it like text, write a bunch, and then run it and … it fails, and then you don’t investigate what happened.

Use console.log to observe what is happening. Find where it goes wrong, find what operation isn’t behaving as you meant.

It’s not about trying different things or copying some other code. It’s about observing what happens and adjusting accordingly.

So, I revised my code again and again and happily felt miserable :slight_smile: I never found out what was wrong with this piece of code of mine, which still showed me in console as zeros:
let reallyCount = 0;
let veryCount = 0;
let basicallyCount = 0;
for (word in storyWords) {
if (word === ‘really’) {
reallyCount += 1;
consol.log(reallyCount);
} else if (word === ‘very’) {
veryCount += 1;
} else if (word === ‘basically’) {
basicallyCount += 1;
}
}
console.log(reallyCount); //shows zero
console.log(veryCount); //shows zero
console.log(basicallyCount); //shows zero

Then I decided that since I wasn’t going anywhere with this, let me go another way. So, I wrote a longer code (unfortunately), I could get what I wanted:

let reallyCount = 0;
let veryCount = 0;
let basicallyCount = 0;

for (i = 0; i < storyWords.length; i++) {
if (storyWords[i] === ‘really’) {
reallyCount += 1;
}
}

for (j = 0; j < storyWords.length; j++) {
if (storyWords[j] === ‘very’) {
veryCount += 1;
}
}

for (k = 0; k < storyWords.length; k++) {
if (storyWords[k] === ‘basically’) {
basicallyCount += 1;
}
}

console.log(reallyCount); //shows 2
console.log(veryCount); //shows 5
console.log(basicallyCount); //shows 1

Now I have mixed feelings I haven’t accomplished what I wanted with less code. On the other hand I found a way to reach the goal by writing a longer one.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.