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 trialNicholas Gaerlan
9,501 PointsWhy is my JSON array object "not defined"?
I'm following along in the video and typing everything exactly as shown but when I log things out to the console I get an error
widget.js:7 Uncaught ReferenceError: employees is not defined
at XMLHttpRequest.xhr.onreadystatechange (widget.js:7)
xhr.onreadystatechange @ widget.js:7
XMLHttpRequest.send (async)
(anonymous) @ widget.js:3
this is a link to my workspace https://w.trhou.se/kdi4xjczd2 and what I have in my widget file:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if(xhr.readyState === 4) {
let empoloyees = JSON.parse(xhr.responseText);
console.log(employees);
}
};
xhr.open("GET", "data/employees.json");
xhr.send();
1 Answer
Charles Wanjohi
9,235 PointsMispell in your declaration
let empoloyees // note this is not employees
Hope it helps.Regards,
Nicholas Gaerlan
9,501 PointsNicholas Gaerlan
9,501 Pointsi saw it right after I posted the question haha. thanks!