Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 14, 2021
Embed
What would you like to do?
Codecademy export
// Write your function here:
const howOld = (age, year) => {
let currentYear = new Date().getFullYear();
const differenceYears = year - currentYear;
const newAge = age + differenceYears;
if (newAge < 0) return `The year ${year} was ${Math.abs(newAge)} years before you were born`
if (newAge > age) return `You will be ${newAge} in the year ${year}`
if (newAge < age) return `You were ${newAge} in the year ${year}`
if (year === currentYear) return `You are ${age} in the actual year`
}
console.log(howOld(28, 1945));
// Once your function is written, write function calls to test your code!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment