Covering Losses


PLease I would like to show how many strawberries was picked but my code doesn´t work!


var earnings = 0;
var berries = 0;
//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 (var strawberries=10; strawberries > 0; strawberries–){
if (strawberries > 0){
earnings = earnings + 2.25;
//Insert inner for loop here
for (var days = 7; days > 0; days–){
for (var berries=0; berries < 10;berries++){
if(berries <10){
berries=berries + 1;
//Boolean that returns true if your losses have been covered
if (earnings >= 225) {
var lossesCovered = true
var lossesCovered = false


Not needed. That line may be removed.

All of those lines may be removed.

That line should be removed.

That should be replaced with,

earnings = earnings + 2.25;    // or, earnings += 2.25

var keywords do not belong in if statements. Declare the variable beforehand.

var lossesCovered = false;
if (earnings >= 225) {
    lossesCovered = true;

This meets the requirements of the instructions. You will learn later on how booleans help us to short-circuit and simplify code.

var lossesCovered = earnings >= 225;

Says it all. No if’s, and’s or but’s. It is or it isn’t. Binary. THat is what to think when looking at an if , for or while conditional. They are all boolean.

console.log(`Losses covered? `, earnings >= 225 ? `Yup!` : `Nope!`);

If you have any trepidations at this point with regard to booleans, stop and spend the time to really dig into the subject. Master the condtional and you master control flow. It’s not something we can gloss over and move on.


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