0

I have functions

      const change = (nameInput, nameError, nameRegexp) => {
        return () => {
          const val = nameInput.value;
          if (!regexp.nameRegexp.test(val)) {
            error.classList.add('animation');
            error.innerHTML = errorMessage.nameError;
            nameInput.classList.remove('correct');
          } else {
            nameInput.classList.add('correct');
            error.classList.remove('animation');
          }
        }
      }
lastName.addEventListener('change', change(lastName, name, name));

The problem is that the nameError, nameRegexp properties are not visible in the middle of the function.

Why is this happening? How to fix this error?

Doe
  • 153
  • 1
  • 3
  • 12
  • You look to be passing the *same* variable, `name`, as `nameError` and `nameRegexp`. – CertainPerformance Apr 16 '19 at 22:26
  • 3
    Well, you're not using them. You're not using `nameError`; you're using `errorMessage.nameError` which is a completely variable. You're not using `nameRegexp`; you're using `regexp.nameRegexp`. I wouldn't be surprised if you were getting errors in the console when you run this as well. – Heretic Monkey Apr 16 '19 at 22:28
  • 1
    What do you bet they meant to do `errorMessage[nameError]` and the like? – Taplar Apr 16 '19 at 22:30
  • **regexp** & **error** seems coming from outer space; **nameError** & **nameRegexp** are never used in your function – Mister Jojo Apr 16 '19 at 22:31
  • Possible duplicate of [Access / process (nested) objects, arrays or JSON](https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Taplar Apr 16 '19 at 22:31
  • @HereticMonkey thanks, the problem is solved – Doe Apr 16 '19 at 22:33
  • 1
    plus : addEventListener can't send parameter values – Mister Jojo Apr 16 '19 at 22:33
  • @MrJ the method returns a function, so it is valid in this case. – Taplar Apr 16 '19 at 22:35
  • remove the parameters from the outer function and put them on the inner function instead – Chris Rollins Apr 16 '19 at 22:41

0 Answers0