Question about the banana bread quiz?


#1

I read through the other questions on this topic but they didn’t help clarify my thought process. I had answered with:
bananas = ‘yellow’ ;
numberBananas = 6;
It was correct but I want to be sure that my reasoning was sound rather than it being a lucky guess. I had thought that numberBananas was the age of the bananas and you don’t use green bananas to make the bread. So of course you would need the numberBananas to be higher than 5. Meaning that:
bananas = ‘green’ ;
numberBananas = 10;
Couldn’t be right due to 10 being too high to be green and:
bananas = ‘brown’ ;
numberBananas = 3;
Is also incorrect because 3<5 and would be green and not brown. Is my reasoning sound here? I’m sorry I just want to be sure that I’m learning correctly, rather than realize I just got lucky and don’t understand the concept of the of statement variables.


#2

Here’s the code again:

var bananas;
var numberBananas;
if (bananas !== 'green') {
  if (numberBananas > 5) {
    print("Let's make banana bread");
  }
}

The code reads like this: “If the bananas are not green, then check how many there are. if there are more than 5 of them, then print out the message.” To get the message to print, you need more than 5 non-green bananas.

  • bananas = 'green'; numberBananas = 10; – No. The bananas are not non-green (they are green)
  • bananas = 'yellow'; numberBananas = 6; – Yes. We have more than 5 non-green bananas.
  • bananas = 'brown'; numberBananas = 3; – No. The bananas are non-green, but there are only 3.

The numberBananas is supposed to represent how many bananas you have, but it’s not too important to know that to solve this puzzle (I only use brown bananas when making bread and that’s not the right answer). Although it would be fair to assume that the value of bananas and numberBananas are independent, meaning the values do not affect each other. In the relationship you’re describing, bananas color depends on numberBananas age. If that was the case, it might make sense to calculate color based on age. For example:

if (numberBananas < 6) {
  bananas = 'green';
} else {
  if (numberBananas > 9) {
    bananas = 'brown';
  } else {
    bananas = 'yellow';
  }
}

This doesn’t match the numbers given in the choices, but it does make the color go from ‘green’ to ‘yellow’ to ‘brown’ as the numberBananas goes up.

–Frankie