Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript AJAX Basics (retiring) jQuery and AJAX The Office Status Project Revisited

Why another each() method (which we were told about in "jQuery Basics" doesn't work here?

The console tells me: Uncaught TypeError: $employees.each is not a function. What's wrong with my code?

$(document).ready(function () {
    $.getJSON('data/employees.json', function(response){
        var $ul = $("<ul class='bulleted'></ul>");
        var $employees = response;
            var $li = $('<li></li>');
            if ( $(this).inoffice){
}) // end read

2 Answers

Emmanuel Molina
Emmanuel Molina
9,268 Points

Because $employees.each(function(){}); isn't the correct synthax :) Try $.each($employees, function(){}); instead.

Justin Roberts
Justin Roberts
14,583 Points

Try logging the response. One thing I think it might be is that the response is not a jQuery object (which it has to be to use a jQuery function). JavaScript itself does have an each type function, it's just "forEach" rather than just "each".