Covering Losses


#1

https://www.codecademy.com/courses/introduction-to-javascript/0/5#
Covering Losses, The For Loop

I’m not sure to understand how the inner loops and outer loops are supposed to interact with each other. Can someone define these terms a little more clearly? The description is instructive, but it doesn’t appear to give a strict definition to the intention of this function. Thank you!



//To make up the money you lost from picking rotten strawberries,
//you decide to pick 10 extra strawberries everyday for the next
//7 days.

//Your earnings
var earnings = 2.25;
var berries = 10;

//Fill in the outer loop with an inner loop that loops through
//10 strawberries and increment your earnings by 2.25 for every 
//extra strawberry that you pick
for (var days = 7; days > 0; days--)
{ 
for(berries = 10; berries > 1; berries ++)
earnings=earnings+2.25;
}

//Boolean that returns true if your losses have been covered
var lossesCovered = true;

//Write an if statement that changes the lossesCovered to true
//if the earnings are greater than or equal to 225



#2

Start from zero…

//Your earnings
var earnings = 0;

Pretty much what you have…

//Insert inner for loop here
 for (var extra = 0; extra < 10; extra++) {
     earnings += 2.25;
 }

Start with this set to false…

//Boolean that returns true if your losses have been covered
var lossesCovered = false;
//Write an if statement that changes the lossesCovered to true
//if the earnings are greater than or equal to 225
if (earnings > 225) {
    lossesCovered = true;
}

#3

Thank you so much, this was very clear.


#4

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