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 trialSamuel Kleos
Front End Web Development Techdegree Student 13,728 PointsIs this solution correct? It works but I don't know.
It works but I'm not sure if it's a good approach. I'm trying to learn to be a developer, and I have no idea if I'm creating things that could cause problems in terms of:
- Debugging
- Readability
- Rafactorability
if (request.readyState === 4) {
var employees = JSON.parse(request.responseText);
console.log(employees);
const employeeDiv = document.getElementById('employeeList');
const ul = document.createElement('ul');
ul.classList.add("bulleted");
for (let employee of employees) {
let li = document.createElement('li');
if (employee.inoffice) {
ul.innerHTML += `
<li class="in">${employee.name}</li>
`
} else {
ul.innerHTML += `
<li class="out">${employee.name}</li>
`
}
}
employeeDiv.appendChild(ul);
}
Thank you. 🙏🏼
1 Answer
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 PointsHi Samuel,
I think your codes look correct. The only thing that I might question is the line.
var employees = JSON.parse(request.responseText);
I think you should always use const or let, not var in modern JavaScript. So that it is clear if this variable can be re-assigned or not. I think in this case you could use const.
Great work and happy coding!