So we have almost completed the program quiz section, questions are displayed, we're able to move
on to the next coming questions and also using instant answer, we can check if answer is correct or
not.
Progress is updating.
And finally, we know when the quiz is finished.
So now it's time to allow users from landing page to log in, start quiz and then get a final score,
as it was in case of questions which will create local storage for persons where we will store their
first names, last names and scores.
All right, so the first thing that we want to do is to create personal objects, and for that, I'm
going to create a function constructor, Enquist controller module.
But at first, let's right here comment.
For a person constructor.
And then create a function constructor, call it person.
So each person object will receive ID.
Then first name.
Last name.
And Scott.
OK, let's use this special, this variable, which actually will point to new brain object, this object
will be created using new operator.
So let's write these dots ID.
Equals to.
Then they start first name.
Equals to first name this dot, last name.
Equal to last name.
And finally, this dogs caught.
Equals to.
All right, function constructor is created, and as we mentioned, the data of persons will be stored
on local storage.
Therefore, the next step is to prepare local storage for persons.
We will do it in the exact same way as it was in case of question, lack of storage.
For that, let's create an object and colleagues person local storage.
Again, we need here are three methods for setting items for getting them and also for removing items,
let's create the first method and call it such person data.
Then assigned to its anonymous function.
This method will hold one parameter, and I'm going to write to your new person data.
Then use set it method.
Right, local storage, that set item.
As we know, said Method holds two arguments as the first one, let's insert your personal data.
And that in order to store data as a string, we need to use again, Jason Todd throwing a method.
As you remember, this method stores everything in local storage as Jason's strings and as an argument
for this method, let's pass your new personal data.
All right, now I'm going to create another method for getting data, let's call it get personal data.
Then assigned to it anonymous function again.
Here, we need to use a written statement.
So in order to get store data with its original data type, we have done it once before.
But I just remind you, we have to use Jason that pass method.
And then as an argument, right to your local storage.
Don't use your guess, it's a method and then insert as an argument person data.
All right, and the third method is for removing data from the storage that's created and call remove
person data.
That use anonymous function.
And inside it is removed item method, right, to lock the storage that.
Remove item.
And as an argument against insert person data.
All right, besides that, in order to always to be prepared, the local storage, when the application
starts, we have to use it statements as it was used exactly in the same way in case of question, lack
of storage.
So.
Right.
If statement.
Then.
Person like storage.
That gets personal data triple equals to now.
And if this condition.
Will be true then we need person local storage.
Got a sick person data and as an argument, place your empty, right?
All right, let's test and see what is happening in local storage, go to Browsr.
And check application.
Reload page.
And you see that.
Here appeared new key value pairs in which then will be stored personal data.
All right.
So the storage is prepared and now it's time to create a new method which actually will add persons
on local storage.
We have to do it in cruise control or module inside the original statement.
That's because we want to make this method public.
So it's right after it's finished function, new method and call it X person.
Then assigned to anonymous function.
So in this method, we will create new grant person objects for that, let's declare that first new
variable and call it new person.
And then create the person object using new operator like new person equals.
Two new person.
OK, as we saw function, constructor holds four parameters, ID first name, last name is Score, and
in order to pass proper arguments for new person object, we need to define each of them separately.
Let's start from ID and declare new variable college person ID.
Then let's take a look on Ed's question on local storage function in order to remind you how it was
defined.
So here it is, as you remember, we used your kind of trick away and we will use this approach for
personal idea as well.
So let's go back to that person function.
Create your statement.
And as a condition, we need to indicate the length of a person's data to be greater than zero, so
right person local storage that get person data.
That length.
Is greater than zero.
And then inside liberalises, right person idee.
Equals personal local storage that gets personal data.
So we have access and persons are right, and now we need to get access on the first item of that right
for that, let's copy it.
And then open square brackets and paste.
So in order to get the last item, we need to subtract one to the length of person every right that
length minus one.
OK, now we have access on last item and let's use your ID right dot ID and then we want to add one
target.
All right.
If the condition is false, it means that there doesn't exist any item in it.
Right.
And because of that, we need to use false statements.
And in that statement, I'm going to define person ID as zero.
All right, so the person I do is defined.
Let's pass it as a first argument.
And the next, we have to define first name and last name of user four that we want to create new object
after function constructor, let's name its current person data.
Let's talk first name and last name in an array creates property and call its full name.
Then assigned to it empty square brackets.
So at this point, we're going to define first name and last name as Nick.
And though actually we will get first name and last name of uses from landing page input's, but for
now, just use those temporary values.
All right.
Besides first name and last name parameters, let's define ourselves, call create new property and
call it score and assign to its value as zero, which actually will be increased when user answers correctly
to the question.
OK, let's go back to that personal function and insert a new person object, the rest of the arguments
as a first one.
We need first name, so right, current personal data, that full name.
And then the index number zero.
Then for a last name, let's copy it and just change index number from zero into one.
And as the last arguments, which is called, we need to write current personal data, not Scott.
OK, the next step is to call this function, but before that, that's right, you're concerned that
the new person.
Then go to controller module and invoke that person function, right, Chris, controller, dot that
person.
Then go to Browsr.
Answered the questions, click on Finish Button and you see that we have an in council, it includes
four properties, ID, first name, last name and score.
All right, so the last thing that we have to do in this video is to insert a personal object into local
storage.
At first we had to get access on local storage.
And for that, let's declare new variable and call it person data.
And then assign to this variable.
Person, local storage that gets personal data.
So we have got questions, all right, and now we need to add new person object to that.
Right.
And I'm going to use push method, the right person data that push.
And as an argument.
That's to a new person.
After that, we have to insert back updated eRate in local storage for that we have the right person,
local storage venues, such person data method and as an argument, place you for some data.
All right, let's go to Browsr, reload.
Then click on answer.
Then click on Finish.
Let's check local storage, go to application.
And you see in person data, our person object.
OK, so the lack of storage is prepared and the next that we are going to do is to get dynamically users
first name, last name, also calculate the score and other stuff.
So let's go ahead.