Exercise Tracker - Last test

Tell us what’s happening:
Hello everyone, I would like to ask help for the last test in the Exercise Tracker challenge. I have tried so many things and still not sure what’s wrong in my solution. I passed all tests but the last one(from, to, limit) Am I doing the filter with from, to and limit right?

Your code so far
My replit link

Thanks, Best regards,

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.60

Challenge: Exercise Tracker

Link to the challenge:

Just played around, I haven’t looked at your code, but playing with your interface, I believe your from and to filters are backwards… when I insert a FROM date, you would think it should return everything after that date, but instead it returned everything before that. Same with the TO, I would have thought it returned everything before that date, but instead it returned everything after that date. Or am I confused.

Thanks for taking time to check it. I have tried it and actually It didn’t work. I reviewed my if else for ‘from’ and ‘to’ and still having same problem. Although when I use only “from” it shows me one exercise, but still not the right one.

Glanced at the code… not a deep dive, but it looks like you are trying to sort the date using a string. A date string won’t likely be able to sort by chronologically, because at that point, its like trying to sort the following chronologically:

“Thursday Nov 14th 1932”
“Saturday Mar 9th 2018”

Trying to sort as a string, S would come before T, but I’m not even sure if JS would perform that kind of sort. If you need to sort your results by date cronologically, you’d need to use date objects.

One of the interesting design choices for this project was how to store the date… store it as a string and just output it, or store it as a date, and convert it to a string to output it… the first seems easier, unless you have to perform date math on it… which to sort you’d need to. If you store the date as a string, to do chronological comparisons I’d think you’d need to convert everything to date objects to get the proper response. I’m not exactly sure how you’d do that in a query.

Anothering interesting design choice was how to store the data in your database. One Schema, Two Schemas with one embedded. It seems that you actually used two schemas, but you didn’t embed one to the other… that means they aren’t tied together. It looks like you use your Users object to determine if the user exists and get the username, and then use that username to look up your Exercise… the problem is, there is no real way to tie a list of exercises to a particular user… like if you had two users that used the same username… they would have a unique id, but when you type your id, you’d get all exercises back for that username, even if they aren’t yours.

I also noticed that your return for api/:_id/logs doesn’t return in the format specified in the challenge page… username/id/count/then array of logs. Yours gave me count then array of logs… but if the tests are passing then maybe thats not a hard requirement.

If you’re passing all but the last test, I don’t think a rewrite would be necessary, but as you’re filtering your log response using a query, you may need to research how you can do that using strings for date, or change so it stores date as a date object… or maybe someone else can see a cleaner fix.

If you do want or end up needing to rewrite your schemas… may want to look into subdocuments (kinda confusing, but kinda simple). Basically it ends up being a single schema, with a field that is an array of another type of schema.

Hope some of that helps. Feel like I’m basically pointing out a few problems without a clear cut solution

1 Like

Thanks a lot kinome79! I resolved it by changing the format I saved the dates. It was exactly like you said, I was trying to sort the stringDate. I just changed to normal date type and then I converted it only when I output it, In that case my date now is always saved as Date and just converted to stringDate when I need to output. I appreciate it!

Quickly response, great help, and a nice explanation! Please be there more people like you! Haha.

Have a nice day

1 Like