-
-
Save codecademydev/50366c5542669a21d1535f600be84787 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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