1
00:00:00,450 --> 00:00:01,190
Welcome back.

2
00:00:01,220 --> 00:00:04,620
I hope you had an opportunity to set this up as well.

3
00:00:05,590 --> 00:00:11,560
In this lesson, we are going to be covering some player stats, so we've got that player object, we

4
00:00:11,560 --> 00:00:12,910
need to set up a score.

5
00:00:13,300 --> 00:00:15,980
So it's going to be something that the user can use.

6
00:00:16,510 --> 00:00:20,850
We've also got the player items and we can start that out at 3:00.

7
00:00:21,070 --> 00:00:26,860
So this is the number of lives or items that the player can miss during the gameplay.

8
00:00:26,860 --> 00:00:30,220
And once they hit zero, then their game is going to be over.

9
00:00:30,520 --> 00:00:32,580
So we also need some interaction here.

10
00:00:32,740 --> 00:00:35,500
We need to make the buttons clickable.

11
00:00:35,740 --> 00:00:38,400
So let's do that and then we're going to handle it.

12
00:00:38,410 --> 00:00:45,340
So we've created an array here of the buttons so we can make use of that and loop through the battery.

13
00:00:45,550 --> 00:00:47,560
So we could have also loop through the node list.

14
00:00:47,740 --> 00:00:49,860
So the number of different ways to do this.

15
00:00:50,110 --> 00:00:54,970
So this is a way to put it within an array and then we can loop through the array, we could loop through

16
00:00:54,970 --> 00:00:56,070
the node list as well.

17
00:00:56,320 --> 00:01:04,030
So we're looping through the object play area, the object buttons, and we're using the foreach to

18
00:01:04,030 --> 00:01:05,590
loop through each one of the items.

19
00:01:05,590 --> 00:01:09,940
And as we loop through, then we want to run an anonymous function.

20
00:01:10,060 --> 00:01:15,500
So this can be a function and we'll put item in here and then this is what happens within that function.

21
00:01:15,520 --> 00:01:18,920
So it's just an anonymous function and each one of those items.

22
00:01:18,940 --> 00:01:25,270
So for now, let's console log out the item so we can take a closer look at it and let's loop through.

23
00:01:25,270 --> 00:01:27,790
And there we see that we've got the one button.

24
00:01:28,000 --> 00:01:32,050
So we only have one button in this case, if we had more than one but one button.

25
00:01:32,050 --> 00:01:34,330
And in some games you might want to have more than one button.

26
00:01:34,840 --> 00:01:39,220
So we might have multiple buttons and you'll see that it will list out all of the buttons.

27
00:01:39,520 --> 00:01:40,780
So we only need the one button.

28
00:01:40,790 --> 00:01:44,950
So bring that back down to one button and we're looping through that item.

29
00:01:45,220 --> 00:01:51,910
And then as we're selecting those items, you notice that we do have that element selected and we can

30
00:01:51,910 --> 00:01:53,010
add an event listener.

31
00:01:53,320 --> 00:01:57,250
And this is a great way to add event listeners to your elements.

32
00:01:57,520 --> 00:02:01,120
So we're going to set it up on Click and then we can handle button.

33
00:02:01,600 --> 00:02:09,130
So we'll handle all of the button clicks in and a function called handle button and save that so that

34
00:02:09,130 --> 00:02:16,030
when we refresh it and of course we need to set up that function and for now we'll just set up one as

35
00:02:16,030 --> 00:02:16,720
a placeholder.

36
00:02:16,720 --> 00:02:22,480
So we're not going to have anything happening within here other than a console message and we can just

37
00:02:22,480 --> 00:02:23,390
say hello.

38
00:02:24,220 --> 00:02:29,530
So every time the button gets clicked, then we're going to be outputting hello into the console.

39
00:02:29,830 --> 00:02:34,720
So always make sure that that's working and it's going to really help you out quite a bit as you're

40
00:02:34,720 --> 00:02:40,840
building out the game to try it out and make sure all of this functionality is connecting so that we

41
00:02:40,840 --> 00:02:47,650
know that if we do have any problems later on, that we know that where the problems came in and we

42
00:02:47,650 --> 00:02:50,200
can better troubleshoot any errors that we might have.

43
00:02:50,620 --> 00:02:54,220
So go ahead and add event listeners to all of the buttons.

44
00:02:54,460 --> 00:02:58,090
And of course, I know we only have just the one, but go ahead and add that event.

45
00:02:58,090 --> 00:03:04,500
Listener So it's ready to scale up and add more buttons into our game.

46
00:03:05,640 --> 00:03:11,280
So coming up next, we're going to add another event wiseness that's going to be the dorm content loaded

47
00:03:11,580 --> 00:03:16,590
and that's going to make sure that all of our dorm elements are loaded before we try to access them.

48
00:03:16,770 --> 00:03:21,170
And then when that loads that, we need to build out our game area.

49
00:03:21,420 --> 00:03:23,550
And that's all coming up in the upcoming lessons.

50
00:03:23,680 --> 00:03:24,630
I'll show you how to do that.
