Tell us what’s happening:
I pass all the tests, except for 1. Any assistance would be appreciated.
// running tests A request to
/api/1451001600000
should return
{ unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }
// tests completed
When I go to that page, I get what I would expect:
Your project link(s)
https://boilerplate-project-timestamp-1.frankmckenna.repl.co/
https://boilerplate-project-timestamp-1.frankmckenna.repl.co/api/1451001600000
solution: https://replit.com/@frankmckenna/boilerplate-project-timestamp-1
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36
Challenge: Timestamp Microservice
Link to the challenge:
Sky020
2
Welcome there,
Hint: Look at the return types…
Remember, programming is very specific.
This is the return from the template project
{“unix”:1451001600000,“utc”:“Fri, 25 Dec 2015 00:00:00 GMT”}
My code returns the exact same
Here is where I do the return.
app.get("/api/:date_string", (req, res) => {
let dateString = req.params.date_string;
if (/\d{5,}/.test(dateString)) {
let dateInt = parseInt(dateString);
res.json({ unix: dateString, utc: new Date(dateInt).toUTCString() });
} else {
let dateObject = new Date(dateString);
if (dateObject.toString() === "Invalid Date") {
res.json({ error: "Invalid Date" });
} else {
res.json({ unix: dateObject.valueOf(), utc: dateObject.toUTCString() });
}
}
});
Sky020
5
Expected: unix: 1451001600000
Actual: unix: "1451001600000"
Thanks. That did the trick. I didn’t even notice the difference.
how to send integer type response ?
system
Closed
8
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.