Loops in Javascript



I am trying to grasp loops (sorry, total newbie here) in Javascript, and I don’t feel like I’m getting it at all. I am doing the first loop activity int he Javascript course where it wants me to loop through and toss every fifth strawberry for being rotten. But I don’t have any idea how to do it. It seems that the lesson didn’t really work up to this. Could anyone maybe explain? I’ve been searching forums and online resources for like 3 hours now. I don’t think my code is complete but I’m totally lost. TIA, and sorry if this is super rudimentary!

var goodStrawberries = 500;

for (i=0; i<=500; i++) {

if(i % 5);
(goodStrawberries --);


general syntax if condition:

if (condition){
   // do something

check your curly brackets and semi-colons, its slightly off

to calculate the fifth strawberry the remainder should equal zero, the whole equal zero bit is missing in your code


I might be wrong, but it seems like there’s a space between "goodStrawberries and the “–”


Ok I will try to take these into consideration! Thank you!


I will take those out too! Thanks!


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