Stuck Horribly on Creating a Timestamp Service

Hi Everyone

So, what should have been a 30-min challenge has now been going on for 3 hours, and I am not getting anywhere. I have explored the Date object and methods back and forth, and have tried so many things, and nothing works. I don’t know what I am doing wrong here, but virtually all tests keep failing.

Even differentiating between valid and invalid time parameters isn’t working. Maybe it’s just one of those days, but I’d really appreciate some guidance.

Here is the replit: boilerplate-project-timestamp - Replit
And here is the relevant function (line 28 on the replit):

app.get("/api/:date", (req, res) => {
  let d = new Date(;
//if the date object returned as valid
  if (d !== "Invalid Date") {
    return res.status(200).
        unix: Date.parse(d),
        utc: d.toUTCString()

//if the date object is invalid, but the params are a valid number (ie timestamp)
  if (Number( {
    d = Number(;
    return res.status(200)
            unix: d,
            utc: new Date(d).toUTCString()

//invalid timestamp 
    return res.status(400)
              error : "Invalid Date"

Thank you!

Not sure if you fixed it but your code is passing for me. Are you submitting the correct URL?

If all the tests are failing for you it might be an issue with Replit. Look in the browser console and network tab for any errors.

Hey man, thanks for trying it out. It’s amazing to learn that it worked for you when I got stuck for way too long. Perhaps it really was something with replit (though I did submit the correct url as you specified above).

In the end, I did get it to pass - the issue was with the second if. I needed to add .toString() to the date object:

if (d.toString() !== "Invalid Date")
instead of 
if (d!== "Invalid Date")

It’s a subtle difference, but it taught me the importance of (1) carefully, carefully reading the documentation, and (2) switching to Typescript as soon as possible.