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
Brian McKie
5,111 PointsAjax stage 2 challenge syntax error
I'm trying to figure out this 2nd challenge code without having to look at the answer but I don't understand where the syntax error is coming from. Uncaught SyntaxError: Unexpected token <
Here is my code(sorry for any formatting issues with this message. First time posting):
var xhr2 = new XMLHttpRequest();
xhr2.onreadystatechange = function(){
if(xhr2.readyState === 4){
var rooms = JSON.parse(xhr2.responseText);
var statusHTML2 = '<ul class="bulleted">';
for (var i=0; i<rooms.length; i++){
if(rooms[i] === true){
statusHTML2 += '<li class="full">';
} else {
statusHTML2 += '<li class="empty">';
}
statusHTML2 += rooms[i];
statusHTML2 += '</li>';
}
statusHTML2 += '</ul>';
document.getElementById('roomList').innerHTML =statusHTML2;
}
};
xhr2.open('GET','../data/rooms.json');
xhr2.send();
1 Answer
Mark Josephsen
8,803 PointsLook at line 16. I've added a comment
var xhr2 = new XMLHttpRequest();
xhr2.onreadystatechange = function(){
if(xhr2.readyState === 4){
var rooms = JSON.parse(xhr2.responseText);
var statusHTML2 = ''; for (var i=0; i';
} else {
statusHTML2 += '';
}
statusHTML2 += rooms[i];
statusHTML2 += '';
}
statusHTML2 += '';
document.getElementById('roomList').innerHTML =statusHTML2;
} }; // Not sure what this is. This is probably your error.
xhr2.open('GET','../data/rooms.json');
xhr2.send();
Mark Josephsen
8,803 PointsMark Josephsen
8,803 PointsAlso look at line 5. You have a random single quotation after the last i.