← Back to challenges

The Sweetest Ice Cream

JavaScriptHardclassesnumbersarrays

Instructions

Create a function which takes an array of instances from the class IceCream and returns the sweetness value of the sweetest ice cream.

Sweetness is calculated from the flavor and number of sprinkles. Each sprinkle has a sweetness value of 1, and the sweetness values for the flavors are as follows:

FlavorsSweetness Value
Plain0
Vanilla5
ChocolateChip5
Strawberry10
Chocolate10

You'll be given instance properties in the order flavor, numSprinkles.

Examples

ice1 = IceCream("Chocolate", 13)         // value of 23
ice2 = IceCream("Vanilla", 0)           // value of 5
ice3 = IceCream("Strawberry", 7)        // value of 17
ice4 = IceCream("Plain", 18)             // value of 18
ice5 = IceCream("ChocolateChip", 3)      // value of 8

sweetestIcecream([ice1, ice2, ice3, ice4, ice5]) ➞ 23

sweetestIcecream([ice3, ice1]) ➞ 23

sweetestIcecream([ice3, ice5]) ➞ 17

Notes

  • Remember to only return the sweetness value.
  • IceCream class is provided (check Tests tab).
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Three Arrays!