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

Tell us what’s happening:

it says you should return string “1h ago” and I couldn’t figure out the problem ,please help me!

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);
  const min = Math.floor((currentTime - lastPost) / 60000);
  const h = Math.floor((currentTime - lastPost) / 3600000);
  const d = Math.floor((currentTime - lastPost) / 86400000);

  if(min < 60000){return `${min}m ago`;}
  else if(h < 3600000 && h > 60000){return `${h}h ago`;}
  else{return `${d}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/126.0.0.0 Safari/537.36

Challenge Information:

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

Why are you using such large numbers? For eg: number of minutes should be checked against 60 right? (Not 60000)?

1 Like

this seems to be the one that executes most of the time, considering that you are using minutes for the last 10000 hours

My code passed successfully, thanks @ILM @hbar1st

1 Like

What did you end up fixing?

instead of 60000 and 3600000 u should write 60 and 24 :-
mod edit: solution removed

1 Like

I removed the solution (we don’t want to post solutions here) but I’m glad you worked things out.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.