Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 14, 2021 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/50366c5542669a21d1535f600be84787 to your computer and use it in GitHub Desktop.
Save codecademydev/50366c5542669a21d1535f600be84787 to your computer and use it in GitHub Desktop.
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