fac-17 / week-7-langs

Week 7 Group
https://lang-week7.herokuapp.com/
0 stars 4 forks source link

dom.js form listeners refactor #25

Open samjam48 opened 5 years ago

samjam48 commented 5 years ago

lines 17 - 50 (registerForm listener and loginForm listener).

There is a lot of repeated code that could be refactored.

image

e.preventDefault() could be stated before the if statements so you don't have it written three times.

The generic statement of these three lines could be turned into a function

warning.textContent = "Please enter a username";
registerForm.appendChild(warning);
usernameInput.classList.add("redBorder");

Something like this would make each if statement on line

const warnUser = (message, form, element) => {
   warning.textContent = message
   form.appendChild(warning);
   element.classList.add("redBorder");
}

warnUser("Please enter a username", registerForm, usernameInput)