# Separating good strawberries

The console says my result of the exercise is not correct, and I don’t find the mistkae.

``````

//You have 500 good strawberries, indexed from 1 to 500
var goodStrawberries = 500;

//For every strawberry whose index is divisible
//by 5, decrement the value of goodStrawberries by 1
for(i = 0; i < goodStrawberries;i++)
{
if(i%5===0)
{
goodStrawberries-=1;
}
}
console.log(goodStrawberries);

``````

What am I doing wrong?

Thanks.

You are beginning your `for` loop at index `0`, where you should be beginning it at index `1`.

1 Like

I did that and it still returned a false number.

Change if(i%5===0) to if(i%4===0)

and you’re good to go

How come? I haven’t tested it yet but I don’t understand why using 4 instead of 5.

EDIT: It worked, still idk why.

1 Like

for (var i = 1; i <= 500 ; i++) {
if (i % 5 === 0 ) {
goodStrawberries = – goodStrawberries ;
}
}
console.log (goodStrawberries)

1 Like

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