Grammar checker activity - HELP!


I’m a bit stuck on the grammar checker activity. I’m receiving the following error for step 8, the findIndex() task:

ReferenceError: Cannot access ‘badWordIndex’ before initialization

My code:

let badWordIndex = storyWords.findIndex(function (word) {
  if (word === badWord) {
    return badWordIndex;

Any help would be much appreciated!

This is because you’re trying to return badWordIndex as the output of itself.

When you do this:

let x = ....

you can’t do this:

return x

because you’re defining it and using it at the same time.


Yes I figured it out, have to return true. Thanks!

That may be in the context of this lesson, but the error message you got means “You can’t return x while you’re defining it.”

1 Like