Welcome back.
I hope you had an opportunity to set this up as well.
In this lesson, we are going to be covering some player stats, so we've got that player object, we
need to set up a score.
So it's going to be something that the user can use.
We've also got the player items and we can start that out at 3:00.
So this is the number of lives or items that the player can miss during the gameplay.
And once they hit zero, then their game is going to be over.
So we also need some interaction here.
We need to make the buttons clickable.
So let's do that and then we're going to handle it.
So we've created an array here of the buttons so we can make use of that and loop through the battery.
So we could have also loop through the node list.
So the number of different ways to do this.
So this is a way to put it within an array and then we can loop through the array, we could loop through
the node list as well.
So we're looping through the object play area, the object buttons, and we're using the foreach to
loop through each one of the items.
And as we loop through, then we want to run an anonymous function.
So this can be a function and we'll put item in here and then this is what happens within that function.
So it's just an anonymous function and each one of those items.
So for now, let's console log out the item so we can take a closer look at it and let's loop through.
And there we see that we've got the one button.
So we only have one button in this case, if we had more than one but one button.
And in some games you might want to have more than one button.
So we might have multiple buttons and you'll see that it will list out all of the buttons.
So we only need the one button.
So bring that back down to one button and we're looping through that item.
And then as we're selecting those items, you notice that we do have that element selected and we can
add an event listener.
And this is a great way to add event listeners to your elements.
So we're going to set it up on Click and then we can handle button.
So we'll handle all of the button clicks in and a function called handle button and save that so that
when we refresh it and of course we need to set up that function and for now we'll just set up one as
a placeholder.
So we're not going to have anything happening within here other than a console message and we can just
say hello.
So every time the button gets clicked, then we're going to be outputting hello into the console.
So always make sure that that's working and it's going to really help you out quite a bit as you're
building out the game to try it out and make sure all of this functionality is connecting so that we
know that if we do have any problems later on, that we know that where the problems came in and we
can better troubleshoot any errors that we might have.
So go ahead and add event listeners to all of the buttons.
And of course, I know we only have just the one, but go ahead and add that event.
Listener So it's ready to scale up and add more buttons into our game.
So coming up next, we're going to add another event wiseness that's going to be the dorm content loaded
and that's going to make sure that all of our dorm elements are loaded before we try to access them.
And then when that loads that, we need to build out our game area.
And that's all coming up in the upcoming lessons.
I'll show you how to do that.