why doesn't the howOld() function work?
#9
I FINALLY SOLVED IT!!!

Code:
const date = new Date();
const currentYear = date.getFullYear();
function howOld(age, year) {
  const yearDifference = year - currentYear;
  const newAge = age + yearDifference;
  const yearOfBirth = currentYear - age;
  const yearsBeforeBorn = yearOfBirth - year;
  if (year > currentYear) {
      return `You will be ${newAge} in the year ${year}`;
  } else if (yearOfBirth > year) {
      return `The year ${year} was ${yearsBeforeBorn} years before you were born`;
  } else {
    return `You were ${newAge} in the year ${year}.`;
  }
}

I MADE IT WORK!!!

From now on I'm always gonna map this stuff out on paper before coding it!!!

Thanks guys!!!
Reply


Messages In This Thread
RE: why doesn't the howOld() function work? - by QMark - 04-05-2020, 01:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to split this JS function into smaller ones of make function work? QMark 0 13,672 05-01-2020, 10:58 PM
Last Post: QMark
  why is my function evaluating to null? QMark 10 40,613 04-08-2020, 12:41 AM
Last Post: QMark
  Why learn PHP? Syntax 2 23,007 12-05-2015, 03:34 PM
Last Post: Syntax