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 trialDon Page
4,021 PointsSharing the extra work I have done to improve this solution
// Creating a new button that accepts text to name the text and class name
function newButton(li, txt) {
let button = document.createElement('button');
button.className = txt;
button.textContent = txt;
li.appendChild(button);
}
// declaring the newButton function & using an array of button names.
// Would make it much easier to create new or remove existing buttons
function attachListItemButtons(li, name) {
name = ['up', 'down', 'remove'];
for(i = 0; i < name.length; i += 1) {
newButton(li, name[i]);
}
}
for(let i = 0; i < lis.length; i += 1) {
attachListItemButtons(lis[i]);
}
3 Answers
Steven Parker
231,268 PointsNice refactoring! But I noticed that the "attachListItemButtons" function doesn't need the second argument:
function attachListItemButtons(li) {
const name = ['up', 'down', 'remove'];
Dominic Bishop
Full Stack JavaScript Techdegree Graduate 15,302 PointsThis is brilliant! Its so much easier to understand. Thank you!
Emmie Cole
3,082 PointsI love this! This is so clever. I kept trying to think of an easier way to add the buttons and I'm so glad someone figured it out.
Don Page
4,021 PointsGlad it was useful Emma :)
Don Page
4,021 PointsDon Page
4,021 PointsGood spot! :) You're right, that second argument was left over from before I was pulling the button names from an array.