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 trialZenzi Ali
Courses Plus Student 2,412 PointsMy widget also doesn't appear on the page. I'm not sure where my error is.
I checked other answers and confirmed that widget.js is linked to my HTML page.
var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if(xhr.readyState === 4){ var employees = JSON.parse(xhr.responseText) var statusHTML = '<ul class="bulleted">' for (i =0: i < employees.length; i+=1){ if(employees[i].inoffice === true) { statusHTML += '<li class="in">'; } else { statusHTML += '<li class="out">'; } statusHTML += employees[i].name; statusHTML += '</li>'; } statusHTML += '</ul>'; document.getElementById('employeeList').innerHTML = statusHTML; } }; xhr.open('GET','data/employees.json'); xhr.send();
1 Answer
James Croxford
12,723 PointsHi there, just checked through your code:
//seem to be missing a semi-colon:
var employees = JSON.parse(xhr.responseText)
var statusHTML = '<ul class="bulleted">'
//used a colon instead of a semi-colon
for (i =0: i < employees.length; i+=1)
Those should be your issues with it not working. Don't forget you should switch your variables over to the 'let' and 'const' keywords too!