Unable to pass two tests for the Exercise Tracker Project

Hello Campers!

Here is the link to my glitch project:

Exercise Tracker

I am unable to pass the following tests:

-Each item in the log array that is returned from GET /api/users/:id/logs is an object that should have a description , duration , and date properties.

My project seems to be returning each of these fields correctly, so I’m not sure why this isn’t passing.

The date property of any object in the log array that is returned from GET /api/users/:id/logs should be a string… Use the dateString format of the Date API.

For this one I have used the .toDateString() method as suggested by the project instructions. However I seem to be getting varying results as to whether or not is has been correctly implemented. Maybe I just need another pair of eyes to take a look.

Thank you so much to anyone who can help!

Update:
One test is still not passing, but I appear to have solved the first test that was giving me problems by updating the post of a new exercise to:

app.post(
  "/api/users/:_id/exercises",
  bodyParser.urlencoded({ extended: false }),
  (req, res) => {
    let newSession = new session({
      description: req.body.description,
      duration: parseInt(req.body.duration),
      date: req.body.date
    });
    console.log(newSession);
    if (newSession.date === "") {
      newSession.date = new Date().toDateString();
    } else if (newSession.date !== "") {
      newSession.date = new Date(newSession.date).toDateString();
    }

However I’m not sure if I fixed it correctly. Also I am still not passing the second test.

I was able fix the problem by further tinkering with this section of the code. Here was my final code for the problem section:

app.post(
  "/api/users/:_id/exercises",
  bodyParser.urlencoded({ extended: false }),
  (req, res) => {
    let newSession = new session({
      description: req.body.description,
      duration: parseInt(req.body.duration),
      date: req.body.date
    });
    //console.log(newSession);
    if (!newSession.date) {
      newSession.date = new Date().toDateString();
    } else if (newSession.date) {
      newSession.date = new Date(newSession.date).toDateString();
    }

Thanks to anyone who looked!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.