Math mistake

can i get some help please

There is nothing wrong with your code. You have the exact desired results in the console. I’ve noticed with several of the lessons, that even when my code is exactly the same as the solution, and I mean exactly, that I still get errors like you have showing here. There are bugs in some of the lessons, and the only way to move forward it to click the ‘Solution’ button. Maybe if all of us click the ‘Get Help’ button, and follow the procedure to report a bug, these bugs will get fixed. Sorry there’s no better answer, but rest assured that your code is flawless. It sucks to have to click the ‘Solution’ button, but it’s the only way forward, my friend.

UPDATE: For context, I’m leaving my previous comment as is, but there are flaws in the code I didn’t catch at first glance. My apologies. There are a few exercises that you can’t pass without clicking the solution, but we need to be absolutely sure we’ve thoroughly checked our code before we make that determination.

ok, thanks so much, because i was looking at other examples of codes and i thought mine look to simple probably i should re-write it. good thing i asked. Thanks again!

ps. after i clicked the solution the solution had a part of it that identified the current day and year and also printed to the log via the block code instead of calling its function both of which things weren’t specified in the excercise

1 Like

I feel your pain :confused:

yearDifference = 2019 - year;
yearBorn = 2019 - age;

The year 1982 was 10 years before you were born.

Not sure what the block syntax on line 4 represents.


OOPS! My bad. My first comment is still true, but I didn’t actually look at your code all that closely. I saw the results in the console, and made an incorrect assumption. There are a few flaws. I would reset that exercise, and try again. You’re close, but the main flaw is line 4. The math won’t be the same for calculating how old you will be in a given year and how many years before you were born a given year was or how old you were in a particular year. I’ve included my code from this exercise here, that you can reference if you like, but you should give it another try on your own first. Sorry for misleading you earlier, and props to @mtf for catching the mistake.

const howOld = (age, year) => {
  const difference = 2019 - year;
  if (difference < 0) {
    return `You will be ${age + Math.abs(difference)} in the year ${year}`;
  } else if (difference > age) {
    return `The year ${year} was ${difference - age} years before you were born`
  } else {
    return `You were ${age - difference} in the year ${year}`;