-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateAccountJS.js
40 lines (37 loc) · 1.15 KB
/
createAccountJS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// document.querySelector("#newAccount").addEventListener("click",createAccount);
let form = document.querySelector("form");
let userData = JSON.parse(localStorage.getItem("userData")) || [];
form.addEventListener("submit",function(event){
event.preventDefault();
let data = {
name : form.name.value,
email : form.email.value,
password : form.password.value
}
console.log(data);
if(checkEmails(data.email)===true){
userData.push(data);
localStorage.setItem("userData",JSON.stringify(userData));
alert("Account created successfully");
window.location.href = "signupPage.html";
}else{
alert("Account already Exists");
}
})
document.querySelector("#createAcc").addEventListener("click",goToLogin)
function goToLogin(){
window.location.href = "signupPage.html";
}
function checkEmails(email){
let filtered = userData.filter(function(element){
return email === element.email;
})
if(filtered.length > 0){
return false;
}else{
return true;
}
}
// function createAccount(){
// window.location.href = "createAccount.html";
// }