Created
October 21, 2018 05:06
-
-
Save santosh/6b281696b5261ace4581a499a119cc88 to your computer and use it in GitHub Desktop.
A facebook login replica, in vanilla js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>JavaScript - Replicating Facebook</title> | |
<script src="script.js" charset="utf-8"></script> | |
</head> | |
<body> | |
<p>You are kinda replicating.</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var database = [ | |
{ | |
username: "santosh", | |
password: "qwerty" | |
}, | |
{ | |
username: "arpan", | |
password: "asdfg" | |
}, | |
{ | |
username: "anil", | |
password: "nadiankit" | |
}, | |
]; | |
var newsFeed = [ | |
{ | |
username: "bobby", | |
timeline: "So tired from all that learning" | |
}, | |
{ | |
username: "sally", | |
timeline: "JavaScript is so cool" | |
}, | |
{ | |
username: "santosh", | |
timeline: "Learning web development with JavaScript" | |
} | |
]; | |
var userNamePrompt = prompt("What's your username: "); | |
var passwordPrompt = prompt("What's your password: "); | |
function isUserValid(username, password) { | |
for (var i=0; i<database.length; i++) { | |
if (database[i].username === username && | |
database[i].password === password) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function signIn(username, password) { | |
if (isUserValid(username, password)) { | |
console.log(newsFeed); | |
} else { | |
alert("Sorry, wrong username or password."); | |
} | |
} | |
signIn(userNamePrompt, passwordPrompt); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment