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

JavaScript

Gustavo Winter
PLUS
Gustavo Winter
Courses Plus Student 27,382 Points

How can i do this? -- Refactoring

I have a simple code and i'm refactoring him. One part of them is selecting 4 li each one in an Ul (it's 4 ul in the total). The action of them is Up, Down and Remove, trigger by a button. I give this brief explanation to simplify the use of this code.

Until now my work got here and i'm stuck. At the Developer tools the following diagnostics appears:

Uncaught ReferenceError: li is not defined.

Without further curling, I want to ask. How can i increment/increase the actions on the main key ?

      const actions__Helpers = {
      main: () => {
        for(let i = 0; i < array__Ul.length; i += 1){
          let ul__Siblings = document.querySelectorAll('ul');
          let ul = ul__Siblings[i];
          let ul__Children = ul.children;
          let li = ul__Children[index__Li];
          actions__Helpers[actions](); // < -- [actions] is one of them: 'Up'; 'Down'; 'Remove'
        }
        },
      Up: () => {
            let action = li.previousElementSibling;
            if (action){
            ul.insertBefore(action, li);
            }

      },

      Down: () => {
            let action = li.nextElementSibling;
            if (action){
            ul.insertBefore(action, li);
          }
      },

      Remove: () => {
            let action = li.parentNode;
            action.removeChild(li);
      }

    }

I'll appreciate any help or even a suggest. Thanks