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
Richard Duffy
16,488 PointsHelp!
I keep getting this error:
Uncaught SyntaxError: Unexpected token var
var x1 = new XMLHttpRequest();
x1.onreadystatechange = function () {
if(x1.readyState === 4 && x1.status === 200) {
var room = JSON.parse(x.responseText);
var HTML = '<ul class="rooms">';
for var o=0; i<room.length; o += 1) {
if(room[o].available === true) {
HTML += '<li class="empty">';
} else {
HTML += '<li class="full">';
}
HTML += room[o].room;
HTML += '</li>';
}
HTML += '</ul>';
document.getElementById('roomList').innerHTML = HTML;
}
};
x1.open('GET', '../data/rooms.json');
x1.send();
2 Answers
Aaron Graham
18,033 PointsIt looks like you are missing the opening "(" on your for loop. Try:
var x1 = new XMLHttpRequest();
x1.onreadystatechange = function () {
if(x1.readyState === 4 && x1.status === 200) {
var room = JSON.parse(x.responseText);
var HTML = '<ul class="rooms">';
for (var o=0; i<room.length; o += 1) {
if(room[o].available === true) {
HTML += '<li class="empty">';
} else {
HTML += '<li class="full">';
}
HTML += room[o].room;
HTML += '</li>';
}
HTML += '</ul>';
document.getElementById('roomList').innerHTML = HTML;
}
};
x1.open('GET', '../data/rooms.json');
x1.send();
Richard Duffy
16,488 PointsThanks, it is all fixed now :).