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 trialMateo Buitrago
5,629 PointsI looped trough the response array with "for", what is wrong with my code?
$(document).ready(function () {
var url = "../data/employees.json";
$.getJSON(url,function(response){
var statusHTML = "<ul class='bulleted'>";
for(var i=0;i<response.length;i++){
if(response[i].inoffice){
statusHTML += "<li class='in'>";
} else {
statusHTML += "<li class='out'>";
}
statusHTML += response[i].name + "</li>"
}
statusHTML += "</ul>";
$("#employeeList").html = statusHTML;
});
});
EDIT:
Already found the mistake Instead of
$("#employeeList").html = statusHTML;
is
$("#employeeList").html(statusHTML);
Any more suggestions for my code?
1 Answer
sibal gesekki
3,484 Points$.getJSON('../data/employees.json', function(response) {
var $employeeList = $('#employeeList');
var $ul = $('<ul class="bulleted"></ul>');
$.each(response, function(idx, obj) {
var $li = $('<li></li>');
if (obj.inoffice) {
$li.addClass('in');
} else {
$li.addClass('out');
}
$li.html(obj.name);
$ul.append($li);
})
$employeeList.append($ul);
});