Exercise Tracker 4th test

can’t pass 4th test even though the response seems okay but I don’t get why it doesn’t pass
here’s my code for the 4th test:

  let userId = req.params._id
   let newExerciseItem = new Exercise({
    description: req.body.description,
    duration: parseInt(req.body.duration),
    date: req.body.date
  if(newExerciseItem.date === ''){
    newExerciseItem.date = new Date()
    {$push: {log: newExerciseItem}},
    {new: true},
    (error, data) => {
      let resObj = {}
      resObj.username = data.username
      resObj._id = data.id
      resObj.description = req.body.description
      resObj.duration = parseInt(req.body.duration)
      resObj.date = newExerciseItem.date

and here are my Schemas

let exerciseSchema = Schema({
  date:{type: Date}
let userSchema = Schema({

let Exercise = mongoose.model('exercise',exerciseSchema)
let User = mongoose.model('user',userSchema);
let resObj = {};

Please help, at this point, I have no idea of what’s wrong

Welcome there,

The expected date format is a Date string - hint: look at the Date methods available.

Otherwise, would you mind sharing a link to:

  1. An online, public, live version of your app
  2. All your code

It is difficult to help without that.

Hope this helps

sure! here’s my code Glitch :・゚✧
I changed exercise.date format but it still doesn’t pass the test

okay, I’ve figured it out! date type for Schema should be Date, so you don’t have to format it to String while creating an exercise item, but you have to convert it to String while sending it as json object in response

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