Loops in Javascript


#1

Hello,

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 --);
}


#2

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


#3

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


#5

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


#6

I will take those out too! Thanks!


#7

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