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

Practice Fetch API

Hey guys!! I am practice my Fetch API skills. There is some problem, I followed the tutorial, but every time i fetch the api it gets undefined. I dont know why is keep happening, hope you guys can help me out, thank you so much!!! Code as below:

var result = document.getElementById('result'); fetch('https://portal.iclass.hk/devtest.php') .then(data => data.json()) .then(results => logOut(results));

function logOut(x) { if(x.employee_age <= 25) { result.innerHTML = x.employee_name; } }

1 Answer

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 29,270 Points

Maybe try using asynch/await. I had similar problem recently. I could not access an array. It turned out that I was attempting to do that before an array was ready.