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 trialKatie Shook
12,326 PointsI keep getting an unexpected end of input.
I must have something different than Dave does. Anyone have a moment to take a look and see what is causing my unexpected end of input. It says it is on the last line xhr.send(); This is what is showing in the videos so I'm not sure whats happening. I'm sure its something simple. Thanks everyone.
var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if(xhr.readyState === 4 && xhr.status === 200) { var employees = JSON.parse(xhr.responseText); var statusHTML = '<ul class="bulleted">'; for (var 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();
3 Answers
KRIS NIKOLAISEN
54,972 PointsThere is a missing bracket in the snapshot. There should be two closing brackets before xhr.open()
: one for the if statement if(xhr.readyState === 4 )
and one for the function. If you click a bracket you can see it will highlight along with its match.
}
};
xhr.open('GET', 'data/employees.json');
xhr.send();
Katie Shook
12,326 PointsI should have done that in the first place! Whoops! Here it is! https://w.trhou.se/la8avak0h6
Katie Shook
12,326 PointsAh I must have deleted them on accident. Thank you!!
KRIS NIKOLAISEN
54,972 PointsKRIS NIKOLAISEN
54,972 PointsUsually this is due to a missing bracket but I don't see one in what you posted. It would be easier to tell if you formatted your code using markdown. But I tested your code in the video's workspace and it ran without error.
If you are using a workspace can you post a snapshot? Click the camera icon in the upper right corner, then take snapshot, then post the link created here.