Remove solutions from forum hint articles?
See original GitHub issueEdited by @moT01:
I hope you don’t mind @qaz6209031, but I am changing this issue to discuss the removal of the solutions in the hints. I fixed the original issue described below, see the conversation for the new direction of the issue.
Describe your problem and how to reproduce it:
There are several bugs in freeCodeCamp Challenge Guide: Timestamp Microservice Solutions section All these bugs can be reproduced by submiting the timestamp project with the solution in the hint
This first bug is a typo
if (dateObject.toString() === "Invalid Date") {
res.json({ error: "Invaid Date" });
}
res.json({ error: "Invaid Date" }) should change to res.json({ error: "Invalid Date" })
The second bug is
if (/\d{5,}/.test(dateString)) {
dateInt = parseInt(dateString);
//Date regards numbers as unix timestamps, strings are processed differently
res.json({ unix: dateString, utc: new Date(dateInt).toUTCString() });
}
The res.json({ unix: dateString, utc: new Date(dateInt).toUTCString() }); } should change to res.json({ unix: dateInt, utc: new Date(dateInt).toUTCString() }); } since unix field is expecting a number not a string
The third bug is a runtime error
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client,
I think the original solution is calling res.json() twice if we do a get request on projecturl/api/timestamp/1451001600000
So the simplest way to fix this in my opinion is just add a else condition like the following
if (/\d{5,}/.test(dateString)) {
dateInt = parseInt(dateString);
//Date regards numbers as unix timestamps, strings are processed differently
res.json({ unix: dateInt, 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() });
}
}
Add a Link to the page with the problem: freeCodeCamp Challenge Guide: Timestamp Microservice
Issue Analytics
- State:
- Created 3 years ago
- Comments:30 (30 by maintainers)

Top Related StackOverflow Question
I have submitted a PR with the required changes.
Thank you, @ieahleen. I was actually waiting for someone to assign me the issue. Now I understand. I will go through the contributing docs and also submit the PR.