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!
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
fetch('https://dog.ceo/api/breeds/image/random') .then(response => response.json()) .then(data => console.log(data.message))
Would using them make the code not work?
Jesus Mendoza23,288 Points
When you execute
fetch function, it returns an object that has a few methods on it, including the method
then and the method
catch. In this case, you execute the
fetch function, it returns an object with the
then property on it so you "chain" it. The
thenmethod also returns an object with the
catch methods on it so you can chain
then again and you can keep doing it as many times as you want (because the previous
then method will always return a new object with the methods
catch that you can continue chaining...
This would work too
const promise = fetch('https://dog.ceo/api/breeds/image/random'); // an object with the method then and catch (a few more too) is returned from this function call promise .then(response => response.json()) .then(data => console.log(data.message))
Let me know if I didn't make myself clear