Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function howOld(age, year) {
- const dateObj = new Date();
- const curYear = dateObj.getFullYear();
- if (year > curYear) {
- return `You will be ${age + (year - curYear)} in the year ${year}`; // Will this calculate my age in the future?
- } else {
- const ageInYear = age - (curYear - year);
- if (ageInYear > 0) {
- return `You were ${ageInYear} in the year ${year}.`;
- } else {
- return `The year ${year} was ${Math.abs(ageInYear)} years before you were born.`;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement