Docking Pay - Issue


I seem to be stuck at this exercise

//Now, given that you picked 100 rotten strawberries and that a 
//strawberry is worth $2.25, use a loop again to calculate your 
//pay losses
var payLosses = 0;

I understand the need to use a for function, but I’m unsure what to use afterwards or how to tie this to the strawberries. Should I define another variable?


Please remember to include a link to the exercise when posting a question in Q&A. Thanks.

use a loop to calculate your pay losses

The above does not imply using a function, just a loop. When we can see the lesson it will be easier to proceed.


Here is a link to the exercise. I’m stuck too. Thanks!

for (var i = 1; i <= 500; i++) {
    if (i % 5 === 0) {
        payLosses += 2.25;


Why is that so? your code i mean!

why the if statement and (i % 5 === 0) in calculating payLosses? since 100 rotten strawberries had already been found!


It is to humor the course author who seems to want us to use the modulo operator and a for loop in this exercise. Given the numbers, 500 and 5, and the amount, 2.25, it all fits together to accumulate paylosses to, 225. Also, it’s the only thing that justifies using a loop, else we could just go,

paylosses = 2.25 * 100

which defeats the purpose of the lesson… To practice with for loops.


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