Welcome to the Treehouse Community
Looking to learn something new?
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,274 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