1
00:00:00,150 --> 00:00:05,040
So last time we left off with a function where we could click the elements and these are the existing

2
00:00:05,040 --> 00:00:10,410
elements and we have an option, we get this X where we can delete them from the page.

3
00:00:10,410 --> 00:00:14,880
And if you go into inspect, you can also see that this gets deleted out.

4
00:00:15,120 --> 00:00:17,310
So that element gets completely deleted.

5
00:00:17,430 --> 00:00:22,580
And the whole list item that gets deleted whenever you click the span's with the X inside of them.

6
00:00:23,070 --> 00:00:29,430
And also when you click on the element itself, we have the class of red being added and that gives

7
00:00:29,430 --> 00:00:32,010
us that strikethrough and the red X..

8
00:00:32,460 --> 00:00:34,080
So let's finish this application.

9
00:00:34,080 --> 00:00:38,660
And the other thing we need to do is have the ability to add items into the list.

10
00:00:38,970 --> 00:00:42,540
So we're going to add that in and we're going to create a function in order to handle that.

11
00:00:43,470 --> 00:00:51,990
So we've already selected that input element within the input select object so we can use that, adding

12
00:00:51,990 --> 00:00:53,370
an event listener to it.

13
00:00:54,690 --> 00:01:00,630
And the event listener that we're going to add is going to be the key process because we're not adding

14
00:01:00,630 --> 00:01:01,760
in a button.

15
00:01:02,850 --> 00:01:10,950
Instead, we're going to detect the key press by checking to see if the user has pressed the enter key,

16
00:01:11,190 --> 00:01:14,010
and that's going to give us the ability to enter in.

17
00:01:14,730 --> 00:01:16,110
So we're adding an event listener.

18
00:01:16,740 --> 00:01:21,170
The event listener that we're listening for is key press on that element.

19
00:01:21,510 --> 00:01:27,420
We're going to do an anonymous function passing in the event object as event, and we're going to listen

20
00:01:27,420 --> 00:01:32,880
for the enter key and enter key, as we saw before, has a key code.

21
00:01:33,000 --> 00:01:35,470
And the key code for the enter key is 13.

22
00:01:35,940 --> 00:01:44,190
So any time the user is on that input field and they press enter, it's going to add the new item.

23
00:01:44,340 --> 00:01:45,990
That's the event that we're listening for.

24
00:01:46,180 --> 00:01:51,450
So any of the key events, any other anything other than 13, nothing is going to happen.

25
00:01:51,900 --> 00:01:59,580
And once it gets invoked, we're going to invoke once it gets clicked, we're going to create a new

26
00:01:59,580 --> 00:01:59,960
function.

27
00:01:59,970 --> 00:02:02,060
We're going to evoke a new function called Make New.

28
00:02:03,480 --> 00:02:07,880
So we've got a function make and I'll scroll this up so we can see it a little bit better.

29
00:02:09,030 --> 00:02:15,360
So within the make you function, this is where we're going to create a brand new list item using document

30
00:02:15,810 --> 00:02:16,950
create element.

31
00:02:18,640 --> 00:02:24,460
And the element that we're creating is a list item so that we can add it to our unordered list and for

32
00:02:24,460 --> 00:02:30,400
the list item, we want to add an event listener, the event listener that we're adding and we're listening

33
00:02:30,400 --> 00:02:31,680
for is the click event.

34
00:02:32,710 --> 00:02:37,360
And whenever it gets clicked, it's going to evoke the function, my list.

35
00:02:37,630 --> 00:02:39,160
And that's the one that we have down here.

36
00:02:39,490 --> 00:02:43,690
So this list item will function the same way as all the existing ones.

37
00:02:43,840 --> 00:02:47,260
Whenever we load the page, they're going to all function within the same way.

38
00:02:47,710 --> 00:02:50,070
We need to add text node.

39
00:02:51,040 --> 00:02:53,140
So we need to get a text value.

40
00:02:53,440 --> 00:02:57,310
And the text value is coming from the input select element.

41
00:02:57,640 --> 00:03:02,470
And whatever value is contained within that input is going to be our new value that we're adding into

42
00:03:02,470 --> 00:03:02,920
the list.

43
00:03:03,310 --> 00:03:07,210
And we also want to clear out that value and the way that we can do that.

44
00:03:07,220 --> 00:03:12,210
So just as we can get the value, we can set the value and we want to just set the value to be blank,

45
00:03:12,880 --> 00:03:18,130
then we're going to create our temp node in order to create a text node.

46
00:03:18,130 --> 00:03:19,930
So document create.

47
00:03:20,930 --> 00:03:27,680
Text Noad and then within there, this is where we're going to use that text value and taking the last

48
00:03:27,680 --> 00:03:35,010
item that we've just created using Append Child, we can attend the temp node that we just created.

49
00:03:35,420 --> 00:03:42,500
So adding in the text into the list item and you can console log out the list item before we add it

50
00:03:42,500 --> 00:03:43,110
to the page.

51
00:03:43,670 --> 00:03:47,570
So now whenever I've got anything written in there, I'm pressing the enter key right now.

52
00:03:47,720 --> 00:03:49,990
We see we've got that list that gets created.

53
00:03:50,180 --> 00:03:53,060
So all we want to do is take the mean list.

54
00:03:53,360 --> 00:03:59,930
So that's the unordered list and use append child to append that freshly created list item to the end

55
00:03:59,930 --> 00:04:00,460
of the list.

56
00:04:00,470 --> 00:04:01,260
So let's try that.

57
00:04:01,700 --> 00:04:06,590
So we've got test and we've got bananas, milk, bread and test.

58
00:04:06,800 --> 00:04:11,930
So test doesn't look quite right, but we click it, we see we have the X and we can remove it from

59
00:04:11,930 --> 00:04:12,500
our list.

60
00:04:12,770 --> 00:04:15,870
So let's try that one more time on the bigger screen refresh.

61
00:04:16,160 --> 00:04:22,040
So typically, if you're going to the store, you've got bananas, bread, and how about you get some

62
00:04:22,040 --> 00:04:30,440
apples and some carrots and you can create as many items in the list as you need and also add in water

63
00:04:31,220 --> 00:04:31,850
drinks.

64
00:04:32,120 --> 00:04:35,000
So whatever you want, you can add into your grocery list.

65
00:04:35,150 --> 00:04:40,250
And if you do make a mistake, you can click the item or if you've already retrieved the item, you

66
00:04:40,250 --> 00:04:42,800
can click it as you go through your grocery list.

67
00:04:42,950 --> 00:04:45,950
And you can also remove it from the list by clicking the X.

68
00:04:46,140 --> 00:04:49,970
So any one of the items, one in one of the elements, they're going to function the same way.

69
00:04:50,090 --> 00:04:52,190
So solution to this challenge.
