-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (39 loc) · 1.42 KB
/
script.js
File metadata and controls
44 lines (39 loc) · 1.42 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
const usersTable = [
// Note: This is a fake table for educational purposes. Never store user credentials in plain text.
{ id: 1, username: 'hello@world.com', password: 'badpassword' },
{ id: 2, username: 'test@user.com', password: 'badpassword' },
{ id: 3, username: 'email@domain.com', password: 'badpassword' },
];
let renderSuccess = () => {
document.getElementById('success-message').hidden = false;
};
let renderError = () => {
document.getElementById('error-message').hidden = false;
};
let resetMessage = () => {
document.getElementById('success-message').hidden = true;
document.getElementById('error-message').hidden = true;
};
addEventListener('submit', (event) => {
event.preventDefault();
resetMessage();
let email = document.getElementById('email').value;
let password = document.getElementById('password').value;
console.log(`email submitted: ${email}`);
console.log(`password submitted: ${password}`);
/*
TODO:
1. Check if the email and password are valid (using the usersTable)
2. If they are, call renderSuccess()
3. If they are not, call renderError()
*/
/*The find method iterates through the usersTable array and checks if there’s an object where both username (email) and password match.*/
const user = usersTable.find(
(user) => user.username === email && user.password === password,
);
if (user) {
renderSuccess();
} else {
renderError();
}
});