Help w/ exercise in Loops?


#1

https://www.codecademy.com/en/courses/introduction-to-javascript/0/3#

I’m completely lost as to what to do here, I know I’m doing the format for the loop all wrong but I don’t know how.



//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(goodStrawberries = 500; goodStrawberries <= index % 5; 
goodStrawberries = 500 - 1)
{
execute command;
}



#2
for(i = 0; i < 10; i++) {
//i **begins** with the value 0.
//i **ends** with the value <10
//i **increments** with every "iteration" or loop runs
 if(i%5===0) {
//the indice increments from 4 to 5 in a loop run or "iteration"
 console.log("This indice is divisible by 5");
 }
}

@objectslayer94127 the code above should help with formatting and also logic
to better understand what and how a for loop works I recommend this quick resource


and

best of luck and happy coding :tada:


#3

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