Exercise Tracker challenge

Tell us what’s happening:
Hello,
I experienced this problem some timeback while doing the exercise tracker challenge. Every test passed except one but I dont understand why it did not pass because it looks fine to me. I will appreciate if someone helped.
This is the test message, “I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.”

Your code so far
https://glitch.com/edit/#!/parallel-recondite-bead

Your browser information:

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

Challenge: Exercise Tracker

Link to the challenge:

Hi,
I just gave this a quick test.
You are returning the full UTC string for the date.
I think this test specifically for just the date part.
Try using the toDateString() method instead when setting the date field on your response?

I used the toDateString and it displayed the date only but the test didnt pass.
I also tried using the toISOString to display the correct date format

https://parallel-recondite-bead.glitch.me

Your date still needs to be in the UTC Date form using toDateString() to pass.
The problem was you were also missing your username field in the response. Add that and it should work.

// can add exercise to any user by pushing form data
app.post("/api/exercise/add", (req, res) => {
  const { userId, description, duration, date } = req.body;
  
  const dateObj = date === '' ? new Date() : new Date(date);
  
  const newExercise = {
    _id: userId,
    username: getUsernameById(userId),
    description,
    duration: +duration,
    date: dateObj.toDateString()
  }
  
   exercises.push(newExercise);
  
   res.json(newExercise);
  
  });

Wow. It worked !!
I think the username field was the main problem.
Thank you so much.

1 Like