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 trialLarry Gonzales
10,112 PointsCode won't show correctly in the browser.
After typing all the code, and viewing in the browser, content won't show the way it should in the browser, am I missing something?
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readystate === 4) {
const employees = JSON.parse(xhr.responseText);
const statusHTML = '<ul class="bulleted">';
for(const 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();
Edited By Dane E. Parchment Jr. (Moderator) - P.S. Please make sure you use code tags on your code examples to make them more readable.
1 Answer
Antti Lylander
9,686 PointsI believe you cannot use const
in a for loop like you have. Don't know whether you have any other problems there. It would be easier to find the error if you posted the whole workspace as a snapshot.
statusHTML needs to be declared with let
also