Whenever the button is clicked, what we want to do is we want to get the values from the inputs and
creating that in an object because we're going to need to make use of it as we apply our conditions
for the different button actions that we've got so we can loop through all of the values we already
have as a node list.
So just as we did with the buttons where we looped each one of them doing the same thing for get values,
so doing enough for each loop for those and returning back, so do the function here.
And you can also get you can also you can get the value of the item as well as you can get its index
value if you need to within this type of loop.
So when we output and we loop through, you can see that the item is going to have a value and also
console like its index value.
So if you do need the index value, it is an option within the for each loop.
So you see when we click it, we get the value of the index as well as the element value and we can
use this in order to create our objects.
So next to that we want to do is we want to get the I get the attribute, so get attribute and the attribute
name of that particular element.
That was that input.
So we're going to return back kookie name, kookie value kookie expire from those inputs and we can
also utilize those as a cookie name.
And we can also specify that we can add that into the object because of course we can always get that
object value.
So adding it and we need one more bracket there.
So instead of the item get attribute, we can get the value of that item.
And there is one thing that we do need to do in case the item is going to be one of the expiry dates.
And I'll show you what's going to happen here, because we can't exactly get the value we need to turn
this into a date object.
And there's an option for that where we can get the value as date.
So as we're iterating through, this value is going to be different depending on what type of input
it is.
So let's create an object in order to house.
These are temporary values in order to house these.
So instead of console logging it out, we're going to create a temp name.
So this is the temporary name of the cookie.
And then we also want to have another one for temp value.
And this is going to be a ternary operator where we're checking to see if temp name is equal to sort
of temp name is equal is not equal to.
And that's Cookie.
Expire, so we're grabbing and checking to see if it's not equal to kookie expire and if this condition
is true, then we're just going to grab the item as the item value.
And if it's not true, we can also remove out these extra brackets because we don't need them anymore.
So you can remove them from both of those statements.
So we're setting the value of temp name temp value to be the item value.
And if it is the cookie expire, we're getting the value as D.
And lastly, let's build an object out of this so that we can utilize that.
So let's create our input value.
We can maybe just call this V, so this is going to be the value of all of the inputs and to add that
in.
So we've got a temp name.
So setting that object value to whatever the temp value is and what this is going to produce, this
is going to produce an object of all of the contents of the input.
So let's try that out and go into a refresh.
So if we click any one of these buttons, you can see that we've got the cookie expire.
So this isn't a date object format.
And you can see it's Monday, February 18th and the GMT time.
So if you adjust that and you do another one, you see it's GMT time.
So that's why it's it's subtracting the GMT time.
So it's updating it and it knows that this is the value that's being associated with the input.
We also get the cookie name, so let's test names.
So if you update that and if you get it again, then you get the new cookie name and we get the cookie
value.
So essentially what we did is we're creating an object that we can use as we apply different conditions,
depending on what button got clicked.
And that's where we know where we can create those cookie interactions.
So go ahead and add this into your project.
So loop through the inputs and create an object out of the input values and be careful of this one value
as date, because if you don't include the value as date, what you're going to get is just the string
value of the expiry.
And that's not going to be really useful if you're trying to set the cookie as a date.
So those that's going to be expecting a date value.
So that's why you need to make sure that you've got the format right.
So you're ready to add the cookie and add the expiry date for the cookie when you do set.
So that's still all yet to come.