← Back to challenges

Father and Son Ages

JavaScriptHardalgorithmsnumberslanguage_fundamentals

Instructions

Create a function that takes two arguments: a father's current age fAge and his son's current age sAge. Сalculate how many years ago the father was twice as old as his son, or in how many years he will be twice as old.

Examples

ageDifference(36, 7) ➞ 22
// 22 years from now, the father will be 58 years old and his son will be 29 years old.

ageDifference(55, 30) ➞ 5
// 5 years ago, the father was 50 years old and his son was 25 years old.

ageDifference(42, 21) ➞ 0

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Tallest Birthday Cake Candles