-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctional.js
More file actions
48 lines (43 loc) · 1.41 KB
/
Copy pathfunctional.js
File metadata and controls
48 lines (43 loc) · 1.41 KB
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
41
42
43
44
45
46
47
48
// THESE JS FILES ARE ABLE TO EXECUTE EXACTLY SAME TASKS WITH DIFFERENT APPROACHES
// TASKS:
// 1-TAKE INPUTS WHICH ARE EMAIL AND PASSWORD
// 2-CHECK THAT EMAIL EMPTY OR NOT
// 3-CHECK THAT PASSWORD IS EMPTY OR NOT IF IT IS NOT EMPTY IT HAVE TO INCLUDE MORE THAN 5 CHARACTER
// 4- IF ALL THE CONDITIONS ARE SATISFIED CREATE THE USER AND LOG THEM
const logUser = (user) =>{
console.log(user)
}
const createUser = (condition,email,password) =>{
if(condition){
const user = {
email : email,
password : password
}
logUser(user)
}else{
alert("wrong credentials!")
return;
}
}
const validation = (email,password,min)=>{
const conditionOne = (email === "" ? false : true);
const conditionTwo = (password < min ? false : true);
return (conditionOne&&conditionTwo);
}
const takeInputs = () =>{
const emailInput = document.getElementById("exampleInputEmail1")
const passwordInput = document.getElementById("exampleInputPassword1")
const email = emailInput.value.trim()
const password = passwordInput.value.trim()
const condition = validation(email,password,6)
createUser(condition, email,password)
}
const checkCredentials = (event)=>{
event.preventDefault();
takeInputs()
}
const getForm = () => {
const form = document.getElementById("inputs")
form.addEventListener("submit", checkCredentials)
}
getForm()