This video I have a fun and quick challenge for you.
So on this event reference page there are a ton of events as we saw in the last video and I want to
know exactly how many are here.
And I definitely don't want you to count manually so write javascript code to figure out how many of
these events exist on this page.
So I recommend that you just open up the console and start typing some stuff in here.
And the hint that you'll get is that each event is one of these elements.
Whatever these are I don't know what these are but whatever each one of these is corresponds to a separate
event on this page.
So count how many of these there are.
So this problem is a great use for the javascript con..
It covers a lot of the stuff that we've been talking about selecting and looping through things.
So go ahead and give this a shot on your own positive video if you need to.
And then I'll go for solution.
And just a moment.
OK so let's talk about how we could find this out.
How many events are on this page.
My first instinct would be to inspect.
So let's take a look.
These are Tweedy's.
It looks like.
So we have one T.T. there.
OK.
So each event is its own.
TR So you can see.
So that's one event.
This is the next event which is inside of a TR so we can do is just count the number of tiers on this
page.
The problem is there might be some other tables that we don't know about.
So let's see let's do a query selector all.
TR Well let's even just do table.
Let's see how many tables are on the page.
Forgot document.
We have one table here.
OK that looks good we have another table down below where is this one.
Let's see.
OK.
Non-standard events.
OK that's right.
We also want to count those.
And then we also want to count this table which we also got correct.
And this one and then is a table at the bottom.
So these are all the events that we want.
So now that we figured out that the only tables on the page are the ones that we care about.
I was worried they could be using a table over here on the nav bar or somewhere up here.
But it turns out the only tables on the page and therefore the only team is on the page are relevant
to this problem.
They contain these events so we want to do now is select documents or queries like you're all TR And
that would give us all the yours says 306.
So let's open up the first one and we can see these correspond to the individual events.
There is one small problem which is the very first TR is actually the headers here.
So we would have to exclude one from this table and then we have this table down here that also has
headers so we need to exclude that one.
So for every table there's one two three four five really need to subtract five rows because we don't
want these here.
So to figure out how many events are on this page we just need to get the length of all the tiaras So
that list that is returned.
This one here I need to figure out how long that is.
So document queries like your all TR length.
And that gives us $360 on this page.
The only thing we have to exclude those five headers so we could do it like this minus 5.
And that gives us 301.
However that is a little bit hard coded because we're assuming there's always five tables.
What if they added a sixth table of events this would be accounting for all the TR is on the page but
we would still be subtracting 5.
So what we actually want to subtract is the length of how many tables are on the page.
So for every table there is one TR that has the headings on it.
So it will look like this document that queries Lechter all TR hotlink minus.
Document that query selector.
All tables are table hotlink.
And that also gives us three hundred and one.
So this exercise serves two purposes one just to get more practice using the console selecting things
.
And the second one is to show you that there are a ton of events out there way way more than you'll
ever need to use.
But it's good to be aware.
There's apparently 301 but like I said a few years ago it's a pretty small world.
Most of the time you'll use about 10 maybe 15.
But there are apparently 301