OK, as we said in this lecture, we're going to program delete button, so when we click on delete,
the question should be removed from question list and also we should get the default view, as it was
in case of clicking on update button.
All right.
Let's go back to brackets for deleting question.
We need to create new function inside added question list method.
I'm going to use again function expression.
But before that, as it was in case of update question part.
First of all, we need to attach to delete button click event using event handler.
So let's write the items.
Dot question, delete an.
And then right on unclick.
Again, I'm going to be to it in advance function, let's call it valid question.
Then creative function expression, so write variable billett question.
Equals to anonymous function.
Let's at first test how it works right inside the function console that log works.
Then go to the browser, reload the page, then click on added button, click on delete.
And you see that it works, OK, fine, in order to delete item from local storage, we need to get
access on storage question list, which is actually a right.
So that's right.
Get storage question list.
So we have access on an air right now and we need to delete the native question items from that are
right.
For that, I'm going to use again splice method.
Because of that, we need only to delete item and not replace it, therefore supplies method will hold
two parameters.
The first one will be position from where we want to delete the item.
As you know, it's already defined.
So let's pass your place in array.
And as a second parameter, we need to place the number of items we want to delete, which in this case
is one.
So when we delete the item after that, we have to overwrites, updated a right to an old one.
For that, you guess that we have to use again said question collection method.
So.
Right.
Storage question list.
That set question collection.
And of course, as a parameter, this method should hold and updated, right, which is get storage
question list.
OK, let's go to the browser and test how the little question function works without click on add it,
then click on delete button.
Reload the page again, and you said that the question is the latest from the question list.
If we check local storage, let's go to the application.
Then we will find that the question is related from local storage as well, so we can say that function
works, but we have here same things to fix as it was in case of upgrade question part.
So the question is not related dynamically from the list.
And also when we click on delete button, we don't get a default view here.
Let's fix that.
Go to Brackett's.
Actually, we need to pass in this function the exact same stuff as it's in Update's question function.
But I think and you should agree with me that if we copy all of this stuff and paste into that question
function, it won't be a smart decision in order to avoid repeating the same code over again, we can
simply create a new function, then put this code inside this function and then invoke this function
in Update's question function and in delete question function is what makes sense.
All right, let's create a function expression and call it back default view.
That aside to it, anonymous function.
Then cut from Update's question, function A of this stuff and.
Then pasted inside their default view function, also let's organize the code for better visibility.
You see that we have your option elements inside followed, but option elements is created in Update's
question function.
Therefore, because of this collapse, we have not access on that variable anymore.
In order to fix that, let's simply create a new variable.
Let's declare it right for updated options.
And then copy this line of code and assign it to updated options variable.
Also, we need to change of the option elements into updated options.
All right, the only thing that we have to do is to invoke this function in Update's question function
and in question function as well.
Let's do it.
Call this function of the first update question function.
Then do the same in the lead question function.
OK, now everything is ready, let's go to the browser.
Reload the page, click on edit button, then click on delete.
And here we go.
The question is deleted from the question list dynamically.
Also, we have a default view here.
And if we check the local storage.
Will find there an empty array.
All right, great.
We have just finished the entire added question part, it was really big method.
It contained multiple functions.
But at the same time, I'm sure that it was really interesting for you.
OK, let's move on.