Hi, when I run the code it returns all the values as specified in the assignment. When I test the code only one test is not passing. That test 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.
Deployed functionality: https://exercise-tracker-fcc4.herokuapp.com/
GitHub repository: GitHub - jadilovic/exerciseTracker: Exercise Tracker - Back End Development and APIs Projects - FreeCodeCamp
Can anybody help me with this?
Thanks,
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Challenge: Exercise Tracker
Why are you passing 0
to the date constructor?
if (from || to) {
filter.date = dateObj;
}
let nonNullLimit = limit ? limit : 500;
const exercises = await Exercise.find(filter).limit(nonNullLimit).exec();
const log = [];
exercises.forEach((exercise) => {
let exerciseDate;
console.log('date : ', exercise.date);
if (exercise.date === '' || exercise.date === undefined) {
exerciseDate = new Date(0).toDateString();
} else {
exerciseDate = exercise.date.toDateString();
}
console.log('string date : ', exerciseDate);
log.push({
description: exercise.description,
duration: exercise.duration,
date: exerciseDate,
});
});
Thank you very much. You question / comment made me think about the code you referred to. I realized that I do not need this whole block of code before each exercise object is pushed to the array. Also, new Date(0) made my code not pass the test so I changed it to current date when new exercise is created. After that all my tests have passed. All best to you! Cheers!
system
Closed
September 15, 2022, 6:24am
5
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.