Mini Linter Step 4 never Enters Loop

I no longer need help thanks

Are you referring to the right list?
Your loop seems to work correctly for a list of strings named betterWords, but if this is all your code you don’t have betterWords defined.

If this isn’t all of your code, could you please post the rest? I’m guessing there is something missing.

You can use console.log() to test if loops are being entered, if ifs are getting caught, etc.

let overusedWords = ['really', 'very', 'basically'];
let reallyCount = 0;
let veryCount = 0;
let basicallyCount = 0;

for(let i = 0; i < betterWords.length; i++){
  // WILL OUTPUT 'LOOP ENTERED' TO LOG IF LOOP IS ENTERED
  console.log('loop entered');
  currentWord = betterWords[i];
// CHECK VALUE OF CURRENTWORD IN LOG
  console.log(`Current word: ${currentWord}`)
  if(currentWord === 'really'){
    reallyCount += 1;
  } else if [...]

If you run it, you’ll see if it enters the loop in the console, and whether currentWord is getting assigned the correct current word. However, if this is your full code, it can’t enter the loop as-is, because it bugs out at the betterWords.length in the for loop, since betterWords has not been defined.

You didn’t mention any errors though, so if betterWords[] is defined elsewhere, try putting in some console.log()s. Double check that it’s defined somewhere though.

Also, it’s better practice to use let or const when defining a variable. currentWord = betterWords[i]; should be let currentWord = betterWords[i]; if you haven’t defined currentWord anywhere else.

I have it defined up in the project it is just not listed here

Hey! I actually did have "betterwords " in the project it was just not listed I have added it now for your reference.

When I console.log the loop it does not log anything so I know it isnt even entering the loop.

Your loop is working fine if you have a list containing any of the words you are looking for, I think the question most likely is what is inside of your betterWords list.

I’m not familiar with many of JavaScript’s built in functions so off the bat I can’t say I see anything wrong with how you are defining your list, but I would recommend using console.log() to see what it contains.

Thats the frustrating bit I did and I used the original storyWords as the prompt suggests for the project and the count still keeps on coming up at zero.

Can you post all the code written out from the project? I’m gonna guess there is something off about the way you are using .filter(), though I’ll have to do some reading on it.

Okay, so from what I’m understanding,

.filter() is in essence looping through an array, and creating a new array that only includes words from the first array that make it function argument return true.
Then .includes()works on an array and returns true if its argument is in the array.

So your array betterWords should include every word from storyWords that is NOT in unnecessaryWords.

Is this what you are wanting? I’m curious now as to what is in the other arrays you are working with: storyWords, unnecessaryWords, and what values are being places in betterWords based on your usage of .filter() and .includes().

Hi @miriiharding, thanks for sharing your request with the forum.
I have looked through your code. It is syntactically correct. Your problem is in the fact that your betterWords array’s elements ( words ) have not well been fetched from the String variable.
The for loop is being entered. The probable reason why your code is not giving you the expected result is that all your ifs’ conditions inside the for loop are evaluated to a falsy value because the elements/words of the betterWords array still have characters like ! . ; … that are concatenated to then.