Exercise Tracker won't pass 4th test

Tell us what’s happening:

I have looked at the hint post and ensured that my tracker returns the correct json format when a user enters a new exercise, but the test is not passing. Can anyone help me figure out whats wrong? I know the last 3 tests aren’t workign properly, because I have yet to write that part of the program. I am only concerned with the 4th one.

Your code so far
Repl: is here!

app.post('/api/exercise/add',async (req,res)=>{
  //create/save new record for exercise (needs to be different than the other one) 
  //can this return the object? if so, save it to a variable and return it with res.json below!
  let tempDate = undefined
  if (req.body.date){
    tempDate = new Date(req.body.date)
  }else{
    tempDate = new Date()
  }
  createAndSaveExercise(req.body.userId, req.body.description, req.body.duration, tempDate)
  let theUser = await User.findById(req.body.userId).exec()/*, function(err, user){
    if(err){
      console.error('user not found')
      return res.json({"error": "user not found"})
    }else{
      return user
    }
  })*/
  console.log(theUser)
  let user_object= theUser
  res.json({username: user_object.username, description: req.body.description, duration: req.body.duration,_id: req.body.userId,  date: tempDate.toDateString()})
})

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Exercise Tracker

Link to the challenge:

Update!: I have now gotten every other test to pass! The only difference I can see is that my output has double quotes around the json keys, where the example in the hint document does not. I don’t know how to get rid of them! (also I’m not sure if that is the issue?)

According to some other forum posts, I need the Id in an “IdObject” format instead of a string. I have no clue how to do this!!! I’m just using a short string thats been randomized for the id much like I did in my url shortener project.

Please help! in my previous attempt to change the type to ObjectId, I have somehow broken everything, and none of my tests pass

Final Captain’s log:
I am very dumb, as are all of us. I wasn’t sending back a number to the user when they posted an exercise, I was sending a string…

All is fixed

2 Likes

same, solved by doing a parseInt() …