Skip to content
Advertisement

Else If statement not recognizing If statement [closed]

I’m getting an error in my code where one of the else if statements is throwing an error that there is no if statement even though there is

I checked other questions but all of them had the same issue where there was a semicolon after the if statement.

JavaScript

Advertisement

Answer

Your problem lies in a pesky semicolon:

JavaScript

That trailing semi-colon says your entire conditional statement is ending. Thus there’s no associated if for your next else.

Also note that if you’re not otherwise screening, i can go to array.length - 1, which means i+1 would be an out of bounds array access.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement