Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
I am having issues with the last second test case 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 tested my code for each type of inputs such as when no date is supplied and when a date is supplied in (yyyy-mm-dd) format. But somehow while running the freeCodeCamp’s test there seem to be some problem in the date property there are cases where the date stored is “Invalid Date”. I can’t seem to find the workaround for this.

I am handling my date as follows:

let date_input;

if ( === "") { 
    date_input = new Date(;
else { 
    date_input = new Date(;

The response sent is as follows:

                        _id: new_exercise.user_id,
                        username: new_exercise.username,
                        description: new_exercise.description,
                        duration: new_exercise.duration,
                        date: new Date(

Solution Link

Your code so far–exercise-tracker

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

Any luck on figuring this out? I took a peek at your code, but didn’t see anything obvious. I noticed that you were also using toDateString in the GET /api/users/:_id/logs output.

Will never be an empty string, it is a date string or undefined. Your comparison in wrong.

I think if you use the web form to post an exercise, and leave the date blank, then will be an empty string. In the tests, however, it is undefined.

Alright - I think I figured it out. The tests show that the second-to-last test case is using toDateString() to figure out its own, local answer for the Date string, and comparing it against your server’s local answer. They could be different days due to timezone differences. Once I realized that, I just waited until the next morning, and all the tests passed for me.

1 Like

I tried that too, but it didn’t solve the problem so i reverted back to this.

I looked for youtube videos and other forums on the same discussion and i found out that there is a mismatch of timezones and local times which is creating this problem.

yeah, i tried doing that but it didn’t solve my problem.

Great, thanks for the workaround. I’ll try it out.

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