Covering losses


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/introduction-to-javascript/0/5#

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
my code causes the browser window to crash.


//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 = 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--){
 if(days !== 0){
     berries = berries + 10;
    for (var count ; count){
        count = count * 2.25
    }
      
     //Insert inner for loop here
}
}

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

#2

this is an infinity loop:

for (var count ; count)

that will cause the browser to crash, i recommend to fix the loop

we use a loop to increase earnings by 2.25 for each additional strawberry.


#3

I made an edit and tried the below code. It appears to solve the equation, but I’m still getting an error.


//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 = 0;
var strawberries = 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--){
 if(days !== 0){
     strawberries = strawberries + 10;
    for (strawberries; strawberries > 0; strawberries--){
        if (strawberries > 0){
        earnings = earnings + 2.25;
        }
    }
      
     //Insert inner for loop here
}
}

//Boolean that returns true if your losses have been covered
 if (earnings > 225) {
    var lossesCovered = true
}else{
        var lossesCovered = false
    }
    


console.log(strawberries)
console.log(earnings)
console.log(lossesCovered)
//Write an if statement that changes the lossesCovered to true
//if the earnings are greater than or equal to 225

#4

if(days !== 0){ and if (strawberries > 0){ are pointless, we got the loops to handle this conditions.

given how the code is validated, strawberries needs to get assigned 10 inside the for loop:

for (strawberries = 10;

which would also be the most common practice


#5

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