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
Douglas Watts
5,464 PointsMy Employees Don't Show Up
Can someone please check my code:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var employees = JSON.parse(xhr.responseText);
var statusHTML = '<ul class="bulleted">';
for(var i=0;i<employees.length;i += 1) {
if(employess[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();
the <ul> & <li> don't show up.
3 Answers
Douglas Watts
5,464 PointsFor some reason the Forum didn't take all what i typed (typical), for some reason the ul and li are not showing up
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var employees = JSON.parse(xhr.responseText);
var statusHTML = '<ul class="bulleted">';
for(var i=0;i<employees.length;i += 1) {
if(employess[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();
anguswhiston
17,225 Pointsvar xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) { var employees = JSON.parse(xhr.responseText);
var statusHTML = '<ul class="bulleted">'; for(var i=0;i<employees.length;i += 1)
{ if(employess[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();
anguswhiston
17,225 PointsI've just written that in the properly formatted way so people can read it a bit easier. There's a markdown sheet when you go to comment in the forum. It will help people read and reply better. I'm not sure why some of the syntax is coming through highlighted. Haven't fully checked the code but will do later
Douglas Watts
5,464 PointsAlright, since nobody will answer me...i just downloaded the code again witch in itself is confusing. It works but i didn't learn much.