Tell us what’s happening:
Hello,
I experienced this problem some timeback while doing the exercise tracker challenge. Every test passed except one but I dont understand why it did not pass because it looks fine to me. I will appreciate if someone helped.
This is the test message, “I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.”
Hi,
I just gave this a quick test.
You are returning the full UTC string for the date.
I think this test specifically for just the date part.
Try using the toDateString() method instead when setting the date field on your response?
Your date still needs to be in the UTC Date form using toDateString() to pass.
The problem was you were also missing your username field in the response. Add that and it should work.
// can add exercise to any user by pushing form data
app.post("/api/exercise/add", (req, res) => {
const { userId, description, duration, date } = req.body;
const dateObj = date === '' ? new Date() : new Date(date);
const newExercise = {
_id: userId,
username: getUsernameById(userId),
description,
duration: +duration,
date: dateObj.toDateString()
}
exercises.push(newExercise);
res.json(newExercise);
});