Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Posting Data with fetch()

Richard Preske
PLUS
Richard Preske
Courses Plus Student 4,356 Points

Converting a basic AJAX program

https://w.trhou.se/kplfqw47m7

I'm trying to convert one of the projects in the basic AJAX course. I replaced the XHR requests with fetch and promise all and I get no errors. I'm having trouble, however, displaying the data - rooms full, empty and employees in, out. Any suggestions?

1 Answer

Steven Parker
Steven Parker
231,269 Points

I see a few issues:

  • the data items are arrays of objects, and don't have a "message" property (lines 13 & 14)
  • the properties of an array ("for in") are just indexes use the values instead ("for of") (lines 36 & 58)
  • the "name" is a property of the item ("property") and not the array ("data") (lines 42 & 64)
Richard Preske
Richard Preske
Courses Plus Student 4,356 Points

Thanks, I'll check it out. The message property does work though displaying the array of objects when I logged to console - lines 13 and 14. Why?

Got it figured out, thanks again!

Steven Parker
Steven Parker
231,269 Points

Attempting to get a 'message" attribute from an array should give you "undefined". If you see something else, what's the complete code in the callback at that point?