Learn Asynchronous Programming by Building an fCC Forum Leaderboard - Step 23

Tell us what’s happening:

Console is displaying 3 errors
“1. You should return the string “30m ago” when the amount of minutes that have passed is 30 minutes.
2. You should return the string “1h ago” when amount of hours that have passed is 1 hour.
3. You should return the string “1d ago” when the amount of days that have passed is 1 day.
// tests completed”

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const timeAgo = (time) => {
  const currentTime = new Date();
  const lastPost = new Date(time);
  
  minutes = Math.floor((currentTime - lastPost) / 60000);
  hours = Math.floor((currentTime - lastPost) / 3600000);
  days = Math.floor((currentTime - lastPost) / 86400000);

  if (minutes < 60) {
    return `${minutes}m ago`;
  } else if (hours < 24) {
    return `${hours}h ago`;
  } else {
    return `${days}d ago`;
  }
  
};

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0

Challenge Information:

Learn Asynchronous Programming by Building an fCC Forum Leaderboard - Step 23

I wrote this in a completely different way, technically the code I presented above is correct however FCC does not want you to write it out that way. The correct way FCC want’s the code written is like this /const timeDifference = currentTime - lastPost;

const msPerMinute = 1000 * 60;

const minutesAgo = Math.floor(timeDifference / msPerMinute);

const hoursAgo = Math.floor(minutesAgo / 60);

const daysAgo = Math.floor(hoursAgo / 24);

if (minutesAgo < 60) {

return \`${minutesAgo}m ago\`;

}

if (hoursAgo < 24) {

return \`${hoursAgo}h ago\`;

}

return `${daysAgo}d ago`;

};\

Hopes this helps.

1 Like

this is not technically correct, you have ReferenceError: minutes is not defined

1 Like

const currentTime = new Date();
minutes = Math.floor((currentTime - lastPost) / 60000);
hours = Math.floor((currentTime - lastPost) / 3600000);
days = Math.floor((currentTime - lastPost) / 86400000);

Please check again properly. How you declare currentTime vs how you declare minutes, hours and days. declaration keyword is missing.