Please I don't understand why my code is not passing test 6

Tell us what’s happening:
Describe your issue in detail here.
My code works perfectly well on replit, but once submitted on FCC, it crashes saying “Cannot read property username of null”, I don’t know where the null is coming from.

I tried using console.log on this

Blockquote
resObj[‘username’] = updatedPerson.username;

The username is not null, there is a value in it.
Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge:

Blockquote
boilerplate-project-exercisetracker-1 - Replit

Post the link to your code.

Blockquote
boilerplate-project-exercisetracker-1 - Replit

req.body[':_id'] is undefined, did you want req.params? Also it isn’t ':_id' (no colon).

I would also suggest you log out req.body.date it isn’t what you think it is when not supplied.

Edit: Also, when the date is supplied you are supposed to use it and create a date from it.

new Date(req.body.date).toDateString()

1 Like

Please when I log console.log(req.body) this is what I got
ExerciseTracker1
And that was why I used req.body[‘:_id’] to grab the user Id.
Yes I noticed the date is an empty string

Did you try logging it out when submitting? I mean when submitting the project to the test page.

It’s the reason why updatedPerson is null because it doesn’t find the id. When you use the form the id is on the body but when the tests POST to the endpoint it isn’t. You can use req.params or req.url to get the id.

When I fix the id and date it passes the two POST to exercises tests.


Edit: When doing these projects I suggest having the network tab open in the browser and looking at the data when submitting. You can see the payload and responses.

I also think reading the tests is helpful. Ideally, you shouldn’t have to look at the tests but I find it helpful.

1 Like

Thank you Sir, your responses were very helpful and finally was able to pass those tests. I so much appreciate your responses.

1 Like

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