Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
can’t pass the “You can POST to /api/users/:_id/exercises…” task
all other tasks were completed successfully…
Duration is return as a number and Date is return with the correct format

app.post('/api/users/:_id/exercises', (req, res) => {
  const exercise = new Exercise(req.body)
  const user = users.find((user)=> user._id == req.params._id)

  
  exercise.date = req.body.date? new Date(req.body.date).toDateString(): new Date().toDateString()
    
  exercise.user = req.params._id
  exercises.push(exercise)

    const newRes = {
                    username:user.username,
                    description:exercise.description,
                    duration:exercise.duration,
                    date:exercise.date,
                    _id:req.params._id//also tried user._id and .toString()
                   }
  console.log(typeof newRes.username, newRes.username)
  console.log(typeof newRes.description, newRes.description)
  console.log(typeof newRes.duration, newRes.duration)
  console.log(typeof newRes.date, newRes.date)
    console.log(newRes)
    res.json(newRes)

});
string fcc_test_16653837130
string test
number 60
string Mon Oct 10 2022
{
  username: 'fcc_test_16653837130',
  description: 'test',
  duration: 60,
  date: 'Mon Oct 10 2022',
  _id: '6343bd2071c43b5291dd4bff'
}


string fcc_test_16653837141
string test
number 60
string Mon Jan 01 1990
{
  username: 'fcc_test_16653837141',
  description: 'test',
  duration: 60,
  date: 'Mon Jan 01 1990',
  _id: '6343bd2171c43b5291dd4c01'
}

Your project link(s)

solution: boilerplate-project-exercisetracker - Node.js Repl - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

Pls see if this is what you are experiencing

today i submitted the project without any changes and it worked just fine, yesterday i spent over 1 hour trying to make that single task appear as completed

there was a bug that got fixed… so that is probably what you ran into

1 Like

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