Rotten strawberries


Just can’t figure out what the answer of the question is:

//Here is an example of a strawberry index
var index = 20;

//Boolean value rotten
var rotten = false;

//If the index is divisible by five, the strawberry is rotten, so set
//rotten to true. False, otherwise

You’ve worked hard to pick 500 strawberries, but it looks like every 5th strawberry you picked was a rotten one! If each strawberry has an index value, write an if statement that returns true if the index is divisible by 5.

Someone able to provide me the code? PLEASE!


we need to check a condition, which requires an if condition, to check if the strawberry is rotten. else the strawberry isn’t rotten

you can always revisit old exercises if you forgot how to write an if/else statement, or external documentation like MDN (mozzila developers network)

to check if index divisible is by 5, we can use the modulo operator (%)


The first part of the course is very clear with some examples and answers if you don’t know how to write the code. However, I’ve never heard of % modulo operator. Would be great to see the answer and learn from that.



the guidelines state:

We do not tolerate cheating!

Please do not just post answers, or ask for them. Some people may help you by posting some code or showing you errors, but cheating is not tolerated. If we see anybody cheating we will delete the post, and maybe ban your account.

so, what you ask me to do, violates the guidelines. Which as a moderator, i can’t do.

seems @mtf has already beaten me to it, to provide information about the modulo operator so i will just provide info about if/else:

If you need further help, shows us your updated code and explain what you are struggling with


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