Advertisement
diseasehf

randomFunParty howOld Function

Apr 3rd, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function howOld(age, year) {
  2.     const dateObj = new Date();
  3.     const curYear = dateObj.getFullYear();
  4.    
  5.     if (year > curYear) {
  6.         return `You will be ${age + (year - curYear)} in the year ${year}`; // Will this calculate my age in the future?
  7.     } else {
  8.         const ageInYear = age - (curYear - year);
  9.  
  10.         if (ageInYear > 0) {
  11.             return `You were ${ageInYear} in the year ${year}.`;
  12.         } else {
  13.             return `The year ${year} was ${Math.abs(ageInYear)} years before you were born.`;
  14.         }
  15.     }
  16.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement