All right, let's go ahead and continue working on that question on Lucka storage method in this lecture.
We're going to define all the parameters of function constructor, which is declared for creating new
question objects, and after that, we will create that new object.
OK, at first, let's delete this line of code.
We don't need it at this point.
So as you saw in previous lecture at question on work, the storage method holds two parameters new
question, text and options for question text.
We have just one input, so it will have a single value.
But for options, we may have at least two choices in order to get the value we need to use for a loop
and that storage options value in an array.
So before we write up, at first I'm going to create an empty array.
Let's be clear.
The variable and IT options array.
I'm going to use kind of better practice for creating variables, and I recommend you to work in the
same way.
I mean, at first to declare variables together and place them at the top instead of function and then
assign the values to them.
OK, so assign to options, array an empty array.
After that, let's create for loop right variable i.e. equals to zero.
So as you remember, we have selected options using select selector old method, this method, the return
node list which has left property.
So let's use this property to define the number of iterations.
Right.
IE is less than options that length.
And then I plus plus.
OK, now we need your statement to check if the input of option is empty or not, because we need to
add it to area in case if it's not empty.
So.
Right.
If then as a condition.
Right.
Options I don't value not equals to empty swings.
So as we said, if input is not empty, we need to add it to array.
For that, I'm going to use push method right inside.
The Culebras is options are right that push.
And then as a parameter I'm going to pass here options.
I got value.
OK, now test what we got here, right, council deadlock options array.
Then go to the browser, reload the page and write something in input's, for example, option one and
then option two, then click to insert button.
And here we go.
The values of the options are added successfully.
Two options.
All right.
Now it's time to define correct answer.
I mean, which radio button is checked for that?
We're going to use dumb manipulation.
But at first, let's be clear, another variable and college correct answer.
Then we need to use if statement where we will write the proper condition, it will define which radio
box is checked and also if the value of that input is not empty at first, let's take a look at indexed
extremophile and find inputs into radio buttons.
So you see that red, your buttons are placed as previous sibling for option inputs, let's take it
into account and use it in condition.
Right.
If that options, I doubt and I'm going to use your previous element, sibling property.
And now in order to find out if your bottom is checked, I'm going to use property called checked,
which actually returns boolean value.
So if your bottom is checked, then it returns to value.
And if it's not, then returns false.
All right.
As we said, at the same time, we need to check if options the input value is not empty.
So for that, I'm going to use an operator and then the same condition as it was in previous statement.
So write options.
I dot value not equals to Apte shrinks.
So if the button is checked and at the same time it's proper input value is not empty, then it becomes
correct answer.
Therefore, we have to write to your correct answer equals options idot value.
All right.
It's time to test again how it works.
Let's right here in council the correct answer, then go to the browser, reload and again type something
here, for example, option one and option two.
That check button, click insert, and we have your correct answer, so it works fine.
All right, let's take a look on function constructor, which we have declared for creating question
objects.
You say that it holds four parameters, three of them we have already defined.
I mean, question text options and correct answer.
And the last parameter that we need to define is ID.
So let's declare it right question ID.
And for now I'm going to assign to it zero, but a bit later will define it in a different way.
So right question id close to zero.
So all the parameters are defined and now we can create new question.
Object using function constructor.
Let's first declare the variable and call it new question.
And then create an object, right?
No question.
I'm sure you remember how to create a new object, but anyway, I'm going to remind you that for a creating
brand new object using function constructor, we need to use new operator, which actually creates the
object.
And this variable inside function constructor points to that new object and associated those parameters
as properties.
So.
Right.
New question.
In function constructor, we have parameters and now we need to pursue proper arguments.
First parameter was ID, so we need to put your question ID.
Then the second one was questioned text, so actually as an argument, we need to use the value which
we will get from the text area input.
So write a new question, text dot value.
Then third parameter is options, we have defined a right for options.
Therefore, we need to pursue it as an argument.
But options array and the last one is correct answer.
So let's right here.
Correct answer.
OK, let's test and see what new question object looks like.
So right inside console that new question.
Let's go to the browser, reload, then write a simple question.
For example, how are you then as an options.
Right.
Fine.
And but let's check out the correct answer.
Fine.
And click insert and see that in console.
We have an object that's dropped on it.
So this object contains four properties we have here.
Correct answer then ID options property, which contains array with two items.
And then we have question.
Text.
All right, perfect.
The next step that we are going to do is to bind this data to local storage in order to save it permanently.
So let's do it in the next video.