1

I solved this problem using my own code, though mine was a bit longer-winded than this one. When I checked other people's solutions this one came up and I just don't understand it. To my amateur eye it looks like it would return a massive number as my understanding of Math.abs() is that it just returns the value as an absolute number. I would love any help.

Here is the problem:

Your function takes two arguments:

  • current father's age (years)
  • current age of his son (years)

С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).

Their Code:

function twiceAsOld(dadYearsOld, sonYearsOld) {
  return Math.abs(dadYearsOld - 2 * sonYearsOld);
}
Chunky Chunk
  • 16,553
  • 15
  • 84
  • 162
Andrew Lovato
  • 103
  • 2
  • 10

1 Answers1

0

My error was in the order of operations. My mind was seeing ((dadYearsOld - 2) * sonYearsOld) which is incorrect. It is more like (dadYearsOld - (2 * sonYearsOld)). Ok, my mistake. thank you for everyone's feedback!

Andrew Lovato
  • 103
  • 2
  • 10