I have edited your code for readability. When you want to post code on the forum, please enclose it between two sets of triple backticks for legibility.
You have three syntax issues in your code:
I guess this is just a typo?
const is InvalidDate
You are trying to combine traditional function declaration with ES6 arrow syntax. You can only do one or the other.
app.get("/api/:date?", function (req, res) => {
You need to comma-separate key/value pairs in objects.
There is a space between your code , is InvalidDate although my replit fork still ran errors. I have been doing api projects for over two years now and also published to the web , if you run this code in a IDE you may have more luck.
That is absolutely not valid syntax, not for the declaration or the invocation.
I know I asked you before if you had done the JS curriculum and I know you said yes. But you might want to revisit the JS curriculum again as this code points to some fundamental issues with basic JS syntax. It doesn’t matter that it is NodeJS, Express, Mongoose, or is running on a server, it is still just JS.
Why do you keep copying other people’s answers? What does that achieve?
You learn nothing from copying code from others which you don’t understand and which is often incorrect anyway.
All of the code which you write for these certification projects should be your own code and you should understand what you’re writing.
Otherwise, not only are you not learning anything, but you’re also not abiding by the Academic Honesty Policy which you sign in order to be awarded the certifications.
That is not how you write an arrow function. You are missing the tip > of the arrow =>
var listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
The listen callback isn’t closed })
/api/:date?
The ? means it is an optional parameter and as such when the test hits the /api endpoint it matches the /api/:date? as well. You have to either move the /api route up to before the /api/:date? endpoint or handle the missing parameter case in that endpoint.
As an aside, the logic does work but is a little confusing. I’m personally not too crazy about it.
The listener callback is still not closed correctly }) and now you have three new errors.
You didn’t close }) the res.json method or the route handler correctly in the last route and the type of quote you are using around the route path is not correct, it has to be a normal double " or single ' quote. Be careful what type of quote you get when you copy code.
They are all basic syntax errors that you need to be able to spot on your own. Again, I would highly suggest you go back through the JS curriculum again.
If you can’t tell from looking at the code you need to start counting opening and closing symbols. For example, for every ( there should be a ) and for every { there should be a } they need to balance out.
You seem to be brute-forcing code. That is not going to work, you have to learn the language you are using otherwise you will just be wasting time throwing code at the wall and seeing what sticks. That is unproductive and not a long-term viable solution.
Edit: At least go through this tutorial and write the code, do not copy/paste anything
The point of the challenges is not just to pass them. The point is to gain the knowledge required to pass them. Passing this challenge using code you do not understand has absolutely zero value.
The date checker function should look for the string Invalid Date, not InvalidDate. How would you know this? By using the Date constructor and looking at what it returns or by reading the documentation.
You went back to the initial syntax error for the first route handler. See the second post in the thread.
The type of quote you are using in the last route path is still wrong. Look at the syntax highlighting in the Replit editor, look at the color. The string for the route path should be the same orange color as the rest of your strings. Again, it must be "" or ''.
What did I do wrong? https://boilerplate-project-timestamp.tffree.repl.co
const is Invalid Date = (date) => date.toUTCString() === “Invalid Date”
app.get(“/api/:date”, function (req, res) => {
let date = new Date(req.params.date)
if(is Invalid Date(date)){
date = new Date(+req.params.date)
};
The purpose of these courses is to teach you how to code and the purpose of this forum is to support this learning and to offer guidance. When there seems no real attempt to learn from either the course materials or the guidance offered, I don’t think we’re getting anywhere fast.
As has been said before, I’d strongly recommend going back to the Javascript Algorithms and Data Structures course and working through it until you have a solid understanding of basic principles.
what did I do wrong?
const is Invalid Date = (date) => date.toUTCString() === “Invalid Date”
app.get(“/api/:date”, function (req, res) => {
function new Date(req.params.date)
if(Invalid Date(date)){
date = new Date(+req.params.date)
};