1
00:00:00,970 --> 00:00:06,430
Whenever the button is clicked, what we want to do is we want to get the values from the inputs and

2
00:00:06,430 --> 00:00:11,590
creating that in an object because we're going to need to make use of it as we apply our conditions

3
00:00:11,590 --> 00:00:16,870
for the different button actions that we've got so we can loop through all of the values we already

4
00:00:16,870 --> 00:00:18,310
have as a node list.

5
00:00:18,550 --> 00:00:24,700
So just as we did with the buttons where we looped each one of them doing the same thing for get values,

6
00:00:25,390 --> 00:00:30,970
so doing enough for each loop for those and returning back, so do the function here.

7
00:00:31,300 --> 00:00:37,570
And you can also get you can also you can get the value of the item as well as you can get its index

8
00:00:37,570 --> 00:00:40,150
value if you need to within this type of loop.

9
00:00:40,630 --> 00:00:46,480
So when we output and we loop through, you can see that the item is going to have a value and also

10
00:00:46,480 --> 00:00:49,010
console like its index value.

11
00:00:50,530 --> 00:00:54,340
So if you do need the index value, it is an option within the for each loop.

12
00:00:54,570 --> 00:01:00,940
So you see when we click it, we get the value of the index as well as the element value and we can

13
00:01:00,940 --> 00:01:03,400
use this in order to create our objects.

14
00:01:03,730 --> 00:01:12,130
So next to that we want to do is we want to get the I get the attribute, so get attribute and the attribute

15
00:01:12,130 --> 00:01:14,590
name of that particular element.

16
00:01:14,590 --> 00:01:16,540
That was that input.

17
00:01:16,780 --> 00:01:23,590
So we're going to return back kookie name, kookie value kookie expire from those inputs and we can

18
00:01:23,590 --> 00:01:25,930
also utilize those as a cookie name.

19
00:01:26,350 --> 00:01:33,970
And we can also specify that we can add that into the object because of course we can always get that

20
00:01:33,970 --> 00:01:34,980
object value.

21
00:01:34,990 --> 00:01:37,640
So adding it and we need one more bracket there.

22
00:01:38,080 --> 00:01:44,350
So instead of the item get attribute, we can get the value of that item.

23
00:01:44,590 --> 00:01:52,810
And there is one thing that we do need to do in case the item is going to be one of the expiry dates.

24
00:01:52,810 --> 00:01:58,810
And I'll show you what's going to happen here, because we can't exactly get the value we need to turn

25
00:01:58,810 --> 00:02:00,820
this into a date object.

26
00:02:01,270 --> 00:02:04,810
And there's an option for that where we can get the value as date.

27
00:02:05,020 --> 00:02:11,800
So as we're iterating through, this value is going to be different depending on what type of input

28
00:02:11,800 --> 00:02:12,210
it is.

29
00:02:12,430 --> 00:02:14,890
So let's create an object in order to house.

30
00:02:14,890 --> 00:02:17,260
These are temporary values in order to house these.

31
00:02:17,470 --> 00:02:22,510
So instead of console logging it out, we're going to create a temp name.

32
00:02:22,520 --> 00:02:24,790
So this is the temporary name of the cookie.

33
00:02:25,180 --> 00:02:29,260
And then we also want to have another one for temp value.

34
00:02:29,380 --> 00:02:37,420
And this is going to be a ternary operator where we're checking to see if temp name is equal to sort

35
00:02:37,420 --> 00:02:41,080
of temp name is equal is not equal to.

36
00:02:41,740 --> 00:02:43,180
And that's Cookie.

37
00:02:44,440 --> 00:02:51,550
Expire, so we're grabbing and checking to see if it's not equal to kookie expire and if this condition

38
00:02:51,550 --> 00:02:56,050
is true, then we're just going to grab the item as the item value.

39
00:02:56,650 --> 00:03:01,920
And if it's not true, we can also remove out these extra brackets because we don't need them anymore.

40
00:03:02,440 --> 00:03:04,660
So you can remove them from both of those statements.

41
00:03:05,260 --> 00:03:10,510
So we're setting the value of temp name temp value to be the item value.

42
00:03:10,960 --> 00:03:16,360
And if it is the cookie expire, we're getting the value as D.

43
00:03:16,360 --> 00:03:20,020
And lastly, let's build an object out of this so that we can utilize that.

44
00:03:20,030 --> 00:03:24,480
So let's create our input value.

45
00:03:24,520 --> 00:03:31,330
We can maybe just call this V, so this is going to be the value of all of the inputs and to add that

46
00:03:31,330 --> 00:03:31,560
in.

47
00:03:31,750 --> 00:03:34,420
So we've got a temp name.

48
00:03:34,630 --> 00:03:41,080
So setting that object value to whatever the temp value is and what this is going to produce, this

49
00:03:41,080 --> 00:03:46,060
is going to produce an object of all of the contents of the input.

50
00:03:46,690 --> 00:03:49,820
So let's try that out and go into a refresh.

51
00:03:49,840 --> 00:03:55,450
So if we click any one of these buttons, you can see that we've got the cookie expire.

52
00:03:55,460 --> 00:03:57,550
So this isn't a date object format.

53
00:03:57,820 --> 00:04:03,190
And you can see it's Monday, February 18th and the GMT time.

54
00:04:03,970 --> 00:04:08,500
So if you adjust that and you do another one, you see it's GMT time.

55
00:04:08,500 --> 00:04:11,560
So that's why it's it's subtracting the GMT time.

56
00:04:11,560 --> 00:04:17,590
So it's updating it and it knows that this is the value that's being associated with the input.

57
00:04:17,800 --> 00:04:20,410
We also get the cookie name, so let's test names.

58
00:04:20,410 --> 00:04:25,900
So if you update that and if you get it again, then you get the new cookie name and we get the cookie

59
00:04:25,900 --> 00:04:26,270
value.

60
00:04:26,530 --> 00:04:32,950
So essentially what we did is we're creating an object that we can use as we apply different conditions,

61
00:04:33,100 --> 00:04:34,840
depending on what button got clicked.

62
00:04:34,840 --> 00:04:37,980
And that's where we know where we can create those cookie interactions.

63
00:04:38,380 --> 00:04:40,030
So go ahead and add this into your project.

64
00:04:40,160 --> 00:04:48,040
So loop through the inputs and create an object out of the input values and be careful of this one value

65
00:04:48,040 --> 00:04:54,220
as date, because if you don't include the value as date, what you're going to get is just the string

66
00:04:54,220 --> 00:04:55,410
value of the expiry.

67
00:04:55,720 --> 00:05:00,120
And that's not going to be really useful if you're trying to set the cookie as a date.

68
00:05:00,130 --> 00:05:02,430
So those that's going to be expecting a date value.

69
00:05:02,650 --> 00:05:05,950
So that's why you need to make sure that you've got the format right.

70
00:05:06,140 --> 00:05:11,130
So you're ready to add the cookie and add the expiry date for the cookie when you do set.

71
00:05:11,560 --> 00:05:13,620
So that's still all yet to come.
