1
00:00:00,480 --> 00:00:04,410
Welcome back in this lesson, we are going to make our code shorter.

2
00:00:05,540 --> 00:00:10,940
And if you want, you can pause the video here and before I make some updates to the code, try it out

3
00:00:10,940 --> 00:00:12,440
for yourself, I'll give you a hint.

4
00:00:12,710 --> 00:00:18,110
One of the things that we are going to be doing is we're going to be making it shorter because we are

5
00:00:18,110 --> 00:00:19,490
using the same values.

6
00:00:19,490 --> 00:00:27,740
So Barch, Cougar, Lion, and we also have Barch, Cougar, Lion within those classes as well as within

7
00:00:27,740 --> 00:00:29,050
the names of those elements.

8
00:00:29,360 --> 00:00:36,290
So you can see that we do have an option here to really utilize this in a unique way where we can shorten

9
00:00:36,290 --> 00:00:42,320
a lot of our code because there's a consistency there within the naming convention as well as the naming

10
00:00:42,320 --> 00:00:43,840
convention of the classes.

11
00:00:44,030 --> 00:00:47,960
So go ahead and try this out for yourself and I'll show you the solution coming up.

12
00:00:48,710 --> 00:00:55,370
So mainly what we wanted to do is we want to shorten the function where we're sending that value.

13
00:00:55,520 --> 00:01:00,130
So instead of ad style, we're going to say play it.

14
00:01:00,140 --> 00:01:05,450
So that's going to be the function and we're going to pass over the value of lower animal.

15
00:01:05,720 --> 00:01:08,330
And of course, you can shorten these as well.

16
00:01:08,480 --> 00:01:16,370
You can shorten the for loop and you can even shorten the function syntax to the newer format with the

17
00:01:16,370 --> 00:01:16,790
arrows.

18
00:01:17,060 --> 00:01:17,980
But I'm not going to do that.

19
00:01:17,990 --> 00:01:20,920
I'm just going to simply shorten the output within the function.

20
00:01:21,260 --> 00:01:26,900
So instead of having two functions where I'm adding style and playing a sound, I'm going to copy ad

21
00:01:26,900 --> 00:01:33,470
style and I'm going to update this with the playing of the sound, and I'm going to compress it all

22
00:01:33,470 --> 00:01:36,650
into one simple function called Play It.

23
00:01:36,890 --> 00:01:38,600
So still passing over that name.

24
00:01:38,930 --> 00:01:42,350
We're grabbing that active element according to the name.

25
00:01:42,680 --> 00:01:44,960
I can get rid of the console message.

26
00:01:45,470 --> 00:01:50,600
And over here we had a switch statement where we were switching between the sounds.

27
00:01:50,990 --> 00:01:54,170
Well, we don't have to do that anymore where we can take this.

28
00:01:54,410 --> 00:02:03,380
And because we are using the same values that are being set out here instead of sound one and play,

29
00:02:03,650 --> 00:02:13,100
we've got the value of the sound within name so we can break out of their user name and break Brek back

30
00:02:13,100 --> 00:02:14,740
into that string value.

31
00:02:15,140 --> 00:02:20,540
So let's go ahead and try that out with our shortened, more condensed function format.

32
00:02:22,870 --> 00:02:30,490
Refresh the page, and now when we click the buttons, we see that it's going red as well as playing

33
00:02:30,490 --> 00:02:31,660
the appropriate sound.

34
00:02:32,350 --> 00:02:37,690
So go ahead and try this one out for yourself, shorten the code, and you can also apply different

35
00:02:37,690 --> 00:02:39,400
ways to shorten the code as well.
