# Having Trouble with an If Statement in a For loop: JavaScript

Hey everyone,

I am working on a project for a college course, and I’ve run into an issue I can’t figure out with the JavaScript code. The button that I’ve made doesn’t run this function when it’s called. If someone could take a look at this code and help me understand why it won’t work, that would be awesome!

Here’s the code:

``````// Function that will create the array of scores. It will then use the array to arrange and average our grades
function newArray() {

// Making the array to store all of the test scores
var scores = [60, 70, 99, 82, 77, 100, 75, 88, 100, 75]

// The second half of the function, this part will use our array to tell the user how many A's, B's, C's, D's and F's they have

// Making variables to hold the number of each letter grade

// Making the for loop that categorizes the scores and determines how many we have of each
for (var i = 0; i <= 9; i = i + 1){
if (scores[i] >= 90 && scores[i] <= 100 {

}

if (scores[i] >= 80 && scores[i] < 90 {

}

if (scores[i] >= 70 && scores[i] < 80 {

}

if (scores[i] >= 60 && scores[i] < 70 {

}

if (scores[i] < 60 {

}

} // End of for loop

// Writing to the screen the number of each letter grade
// Haven't written this all out yet: will do when I get it to work

} // End of function``````

most of your if statements dont have closing perentheses

1 Like
• You need to be using `else if` after your first `if` statement.

• You’re missing a lot of closing parens `)`

• Fix those and your code will run.

• You may want to think about using `.length` in your loop. This way you don’t have to update your code if more grades are entered (or removed).

• As an aside, you should run your code through a JS validator. It will help you find your typo’s if your editor isn’t picking them up for you.

1 Like

Thanks guys for the feedback, I can’t believe I forgot the closing parentheses around the if’s! I also changed the if statements after the first one to be else if. It still won’t run, however, even if I just call it right in the code.