Creating a mini Facebook, using JavaScript.

Creating the database

I decided to revisit some old concepts in JavaScript that I learnt earlier on, and have definitely learnt more parts this time around. The very small project that I’ve done is basic, but the concept behind it could be replicated on a much bigger level.

The first part of building a mini Facebook was to create my own login details.

I used an array which contains an object with my person login details. I named the array “database”. I then created a news feed and stored the data in the same format as my login details.

Creating the login

I used a simple prompt method to login with my username and password.

Creating the log-in conditions

Now I wanted to access the news feed, I would only be able to see it, if my user credentials were correct, (with what the database was holding). For this, I used a function with 2 parameters and 2 conditionals.

So my function called “signIn”, has 2 parameters, “user” and “pass”. Inside the function I had an if statement that checked if the username I entered, was a strict equality comparison operator against the username stored in the database object, within the array. The username in the array was accessed by finding the first index: [0], and then using .notation to get the username from the object inside.

Next, the same process was used to check the password. If both criteria was satisfied, I would be able to view the news feed, otherwise I would receive an alert message that said “wrong user”.

Calling the function

Finally, I called the function and passed userNamePrompt and passwordPromt as the arguments.

prompt message asking for my username
prompt message asking for my password

The result

Now the news feed appeared in my console, which meant my log in details were correct.

my console showing the Facebook news feed

To check that the function worked if I had entered the wrong details, I gave a wrong password.

prompt input where i entered wrong password
alert message that reads "wrong user"

Thank’s for reading.

Leave a comment

Your email address will not be published.