Here again. My timestamp solution works perfectly. It returns everything as it exactly supposed to do. I asked this question previously and the person who was of most help also could not see why the code wasn’t passing the two tests. IT passes all tests except the last two. Even though it should.
Why isn’t my code passing the last two tests of the timestamp project in API’s and Microservices?
Here is the code:
// your first API endpoint...
app.get("/api/", (req,res) =>{
const date = new Date();
date.setMinutes(date.getMinutes()-3);
res.json({ "unix": date.valueOf(), "utc": date.toUTCString()})
});
app.get("/api/:date?", function(req, res) {
let date_params = new Date(req.params.date);
if(date_params.toString() == "Invalid Date"){
date_params = new Date(parseInt(req.params.date));
}
if(date_params.toString() !== "Invalid Date"){
res.json({ "unix": date_params.getTime(), "utc": date_params.toUTCString()});
} else{
res.json({ "error": "Invalid Date"});
}
});
@hbar1st means the link to your live project code I believe. I bootstrapped what you posted into another repl. The code fails the empty date parameter test, so start with that route and log the inputs and responses:
Thank you so much! Removed that 3 second delay I originally put. I had it there because at first nothing worked in my earlier versions of code unless I put a certain time delay on my code (my logic had something to do with freecode camp processing speed). It worked for my code back then but after re-writing a bunch of times it seems I didn’t need it anymore. thanks alot! everything works!