← Back to challenges

Number of Apples Left

JavaScriptHardlanguage_fundamentalsmath

Instructions

A man has n number of apples. If he eats a percentage p of the apples (if apples are available), his children will share the remainder of the apples. Create a function to determine the number of whole apples his children got. If his children did not get any apples, return "The children didn't get any apples".

Examples

getNumberOfApples(10, "90%") ➞ 1

getNumberOfApples(25, "10%") ➞ 22

getNumberOfApples(0, "10%") ➞ "The children didn't get any apples"

Notes

p will always be given.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find the Missing Number