# Did I do my math wrong?

Gives the proper answers, error at bottom reads: If the year passed in was before the person was born, the function should return: ‘The year [year passed in] was [calculated number of years prior to their birth] years before you were born’

``````// Write your function here:
const howOld = (age, year) => {

const yearDifference = year - 2019;
const newAge = age + yearDifference;
if (newAge < 0) {
return `The year \${year} was \${Math.abs(yearDifference)} years before you were born`;

} else if (newAge > age) {
return `You will be \${newAge} in the year \${year}`;

} else {
return `You were \${newAge} in the year \${year}`;
}};

// Once your function is written, write function calls to test your code!
console.log(howOld(43, 1960))//The year 1960 was 59 years before you were born
console.log(howOld(40, 1994))//You were 15 in the year 1994
console.log(howOld(35, 2025))//You will be 41 in the year 2025
``````

Hello @wynterwolf75. Check your calculation here:

A person who is 43 in 2019 would have been born in 1976, so 1960 would only be 16 years before they were born.

Oohf. I think I was looking so much at the code, I forgot to math. Thanks.

1 Like