Cannot seem to pass the Test for GET /api/users/:id/logs

This is the response what I get when I hit the URL,

{"username":"fcc_test_16448402534","count":2,"_id":"620a453d46a4c9f0c5f6df2d","log":[{"description":"test","duration":60,"date":"Mon Jan 01 1990"},{"description":"test","duration":60,"date":"Tue Jan 02 1990"}]}

Cannot wrap my head around whats wrong in there, my api endpoint looks like this:

app.get('/api/users/:_id/logs', function(req, res){
  const _id = req.params['_id'];
  let responseObject={} ;
  Tracker.findById(_id, (err, result)=>{
    if(!err && result != undefined){
      // console.log('Result: ', result)
      responseObject['username'] = result.username;
      responseObject['count'] = result.log.length;
      responseObject['_id'] = result._id;
      responseObject['log'] = result.log;
    }
    
    // console.log('Response: ', responseObject);
    res.json(responseObject)
  })
  
});

Describe your issue in detail here.

Your project link(s)

solution: https://replit.com/@mi8guy/boilerplate-project-exercisetracker

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge:

You should be seeing an error in the console RangeError: Invalid time value.

Log out date in the exercises route and compare that to what you are checking for in the if statement.

Personally, I would suggest switching the if/else logic and checking for a truthy value.

if (date) {
  // use truthy value
} else {
  // don't use truthy value
}

You will still fail the last test, but you haven’t implemented that logic yet.

Wow! thank you soo much for your help! I checked date with Date.parse(date) and mostly all tests passed !

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