Tell us what’s happening:
Hi everyone! I’m working on the Timestamp Microservice project and am caught on the 5th and 6th tests having to do with an “empty” parameter. So, my understanding of an empty parameter would be that the URL looks like [project_url]/api/timestamp/
, and nothing more. When I use that with my current code (like this), it seems to be functioning correctly, it returns a JSON object with the UNIX and UTC formatted times, however, it’s not passing those tests. Am I not correctly understanding what it means to pass an “empty parameter”?
Your code so far
Here is the Glitch project, I’ll also post just the .get()
function here:
app.get("/api/timestamp/:date_string?", function(req, res) {
var reqString = req.params.date_string;
var resDate;
if (reqString == undefined) {
resDate = new Date();
} else {
if (!/^\d{4}-/.test(reqString)) reqString = parseInt(reqString);
resDate = new Date(reqString);
// this comparision is used to see if the date is a valid date, is there another way to do this?
if (resDate.getTime() !== resDate.getTime()) {
res.json({ error: "Invalid Date" });
}
}
res.json({ unix: resDate.valueOf(), utc: resDate.toUTCString() });
});
Thanks so much for your attention!
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36
.
Challenge: API Project: Timestamp Microservice
Link to the challenge: