diff --git a/src/script.js b/src/script.js index 529f585..7a05c0d 100644 --- a/src/script.js +++ b/src/script.js @@ -19,17 +19,32 @@ let resetMessage = () => { document.getElementById("empty-error-message").hidden = true; }; +let isNewEmail = (email) => { + return usersTable.filter((user) => user.username === email).length === 0; +}; + +let isEmptyEmail = (email) => { + return email.length === 0; +}; + +let addNewEmail = (email) => { + usersTable.push({ username: email }); +}; + addEventListener("submit", (event) => { event.preventDefault(); resetMessage(); let email = document.getElementById("email").value; - // TODO: Show Correct Status Messages on Signup Form - // 1. successful signup - // 2. empty email - // 3. taken email - // 4. repeat email + if (isEmptyEmail(email)) { + renderEmailEmptyError(); + } else if (isNewEmail(email)) { + renderSuccess(); + addNewEmail(email); + } else { + renderEmailTakenError(); + } }); let toggleNav = () => {