Exercise Tracker - Absolutely stuck

I was trying to pass the tests in Exercise tracker under Back End Development and APIs FCC projects but can’t seems to pass the tests. Manually looking at output, it seems to be doing what it is supposed to do.

Code is hosted on replit and can be accessed by you. Please help. You can see index.js file clicking on show files.
Replit code in index.js file

I was able to fix my code to pass all but one test. The change I made was

//_id: req.body[":_id"],    tests fail if I grab _id this way
_id: req.params._id,     // tests pass if I grab _id this way

If someone can explain how this change fixes the problem, that would be great.

The only test that code is failing now is

The date property of any object in the log array that is returned from GET /api/users/:_id/logs should be a string. Use the dateString format of the Date API.

I have verified that Date is of type String and generated using

new Date(<user_input_date_string>).toDateString();

I am reading about timezone offset problem but still stuck and trying to resolve it.

This is the response you are sending for the /api/users/:_id/logs route. In all of them the date is set to "Invalid Date"

    "username": "fcc_test_16929900990",
    "count": 1,
    "_id": "64e8fa94cb8a1d02efa651b9",
    "log": [
            "description": "test",
            "duration": 60,
            "date": "Invalid Date"

You are not handling the optional date correctly. Check what the data property is when there is no date payload.

thank you, when I manually entered exercise leaving date field empty, it worked but I failed to notice that when running tests, the date field can be undefined and not just an empty string. Made following change and now it works. thanks for taking a look.

Changed this

if (dataInput.date === "" )


if (!dataInput.date )

Good that you figured it out.

Usually, when it comes to conditionally checking falsy values you don’t need to check the actual values. You can just rely on type coercion.

There are a few cases to be aware of, like numbers where 0 becomes a false boolean value which might be unexpected.

1 Like