I pass all the tests in this project except but the number 8. I compared mi response with the response in the frecodecamps’s example and is exactly the same .
This is my code:
app.post('/api/users/:_id/exercises', function (req, res){
User.findById(req.params._id, function(err, user){
if(err) console.log(err);
let date = new Date (req.body.date);
if(date.toDateString() == "Invalid Date"){
date = new Date();
}
let exercise = new Exercise({username: user.username, description: req.body.description, duration: req.body.duration, date: date.toDateString(), id: user._id})
exercise.save(function(err, data){
if(err) console.log(err);
res.json({"_id": data.id, "username": data.username, "date": data.date, "duration": data.duration, "description": data.description});
});
});
});
Whit this code i obtain this response:
{"_id":“627c2a02029d90cf7f9e6be0”,“username”:“username”,“date”:“Tue Sep 08 1998”,“duration”:45,“description”:“descripcion”}
and using the example i obtain this response:
{"_id":“627aab9cea23a206a7ea8c0b”,“username”:“username”,“date”:“Wed Sep 12 2012”,“duration”:45,“description”:“descripcion”}
I don´t know where is the mistake.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36
Challenge: Exercise Tracker
Link to the challenge: