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

getting an error: nameActions[action](); is not a function error. Code still runs?

I still get the error in the console saying this is not a function and my text doesn't contain any captilisation.

ul.addEventListener('click', (e) => {
    if (e.target.tagName = 'BUTTON'){
      const button = e.target;
      const li = button.parentNode;
      const ul = li.parentNode;
      const action = button.textContent.toLowerCase();

      const nameActions = {
        remove: () => {
            ul.removeChild(li);
        },
        edit: () => {
            const span = li.firstElementChild;
            const input = document.createElement('input');
            input.type = 'text';
            input.value = span.textContent;
            li.insertBefore(input, span);
            li.removeChild(span);
            button.textContent = 'save';
        },
        save: () => {
          const input = li.firstElementChild;
          const span = document.createElement('span');
          span.textContent = input.value;
          li.insertBefore(span, input);
          li.removeChild(input);
          button.textContent = 'edit';
        }
      };

      // select and run action in a button's name
      nameActions[action]();

    }
  });
});

Here is the error from the console

Uncaught TypeError: nameActions[action] is not a function at HTMLUListElement.ul.addEventListener (app.js:115)