Need Help - Last Project for the Full Stack Certification

Please, can someone indicate what am I missing to pass the “APIs and Microservices Projects - Exercise Tracker” test!???

When I run the code I get this:

All the tests get passed but this:
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.

Can’t think anymore and this is basically the last exercise for me to get the full stack dev certification and I want to do that before the new version is out…

Anyone? Please?

The code is here:

I’m not using a DB for it.

Thanks everyone in advance!

The test is bugged. Don’t sweat over it. Even the ‘official solution’ won’t work for the 4th test case if you paste this URL as a solution. (

If you want to dig deep, you can see how it is being tested:

These tests were added on March 26, 2020 (commit)

1 Like

Your current solution is correct. But if you want to pass the test for the sake of moving forward, you can try the following code:

// POST'/api/exercise/add', (req, res) => {
  const { userId, description, duration, date } = req.body;
  const dateObj = date === '' ? new Date() : new Date(date);
  // Find the username
  const username = getUsernameById(userId)
  // error - if no user is found
  if (!username) {
    res.status(400).json({ error: 'Invalid user ID' })

  const newExercise = {
    _id: userId, // although `_id` should be a unique id, not the user ID, but we have to put userId here just for the sake of passing the test. THIS IS NOT HOW YOU DO IT IN A REAL PROJECT. IDs should (almost) always be unique.
    username, // add username as well.
    duration: +duration,
    // date: dateObj.toString() 
    date: dateObj.toDateString() // `toDateString` just for the sake of this test


I’ve made only minor changes. You can compare your code with this one to get the idea.

1 Like

Thanks very much man… Lovely work! :smiley:

1 Like