1
00:00:00,510 --> 00:00:06,120
So some will tell you a function really isn't a function unless you're returning a value, so it functions

2
00:00:06,120 --> 00:00:08,920
really have the three parts, they have the input.

3
00:00:08,940 --> 00:00:14,520
So this is the data that's sent into the function, the code that gets a run and then also the output.

4
00:00:14,700 --> 00:00:18,870
And this is commonly a value that's returned by the function example.

5
00:00:18,870 --> 00:00:26,340
We've got two numbers that are being passed in and we're returning back the two values, but we're adding

6
00:00:26,370 --> 00:00:27,000
them together.

7
00:00:27,010 --> 00:00:33,390
So we're doing something with the content that's being passed in and returning back, something that's

8
00:00:33,390 --> 00:00:36,590
been computed out of the function, something different.

9
00:00:37,050 --> 00:00:39,450
So we've got a quick math option.

10
00:00:39,600 --> 00:00:45,720
And math is one of the great examples that we can use because it's really simple and we can show you

11
00:00:45,930 --> 00:00:51,510
how you can multiply so you can create a function to do multiplication of any two numbers.

12
00:00:51,730 --> 00:00:56,520
And also notice as well that there is no semicolon at the end.

13
00:00:56,730 --> 00:01:02,240
The semicolon is within the block of code and it's straight after within the return.

14
00:01:02,520 --> 00:01:10,200
So we're all we're doing is we're taking in the two values and then we're taking X times Y and we're

15
00:01:10,200 --> 00:01:12,620
returning back that computed value.

16
00:01:12,930 --> 00:01:19,200
So there is a challenge in this lesson and that's to create a function that multiplies two values and

17
00:01:19,200 --> 00:01:20,580
returns the result.

18
00:01:20,910 --> 00:01:24,770
And ideally, what we want to do is put it into the console.

19
00:01:24,990 --> 00:01:30,750
So something like this where we're calling a function called multiplier and we're passing in the two

20
00:01:30,750 --> 00:01:34,330
numbers and then we're seeing the result being returned back.

21
00:01:34,590 --> 00:01:40,990
So this could be 10 and five or any combination that return back 50.

22
00:01:41,370 --> 00:01:44,400
So go ahead and pause the video, try it out.

23
00:01:44,400 --> 00:01:49,020
And this is a quick peek at what the solution is and I'll walk you through it coming up.

24
00:01:49,260 --> 00:01:52,440
I hope you had an opportunity to try this out for yourself.

25
00:01:52,740 --> 00:01:56,700
And this was a really quick, short example of how to use a function.

26
00:01:57,180 --> 00:01:59,400
And this can be number one.

27
00:01:59,490 --> 00:02:06,960
So we can equal that to one hundred and number two can be two hundred, create our function, taking

28
00:02:06,960 --> 00:02:11,400
in value eight and value B and then returning back.

29
00:02:11,400 --> 00:02:15,990
The result, you can also set up a temporary holder for that as well.

30
00:02:15,990 --> 00:02:22,530
So you could take A and B and then return back temp or you could do it all within one statement.

31
00:02:22,860 --> 00:02:24,330
The result is going to be the same.

32
00:02:24,480 --> 00:02:33,210
And then next we need to consider log out the value of multiplier and we have them as variables so we

33
00:02:33,210 --> 00:02:38,760
can take value of number one and number two and we can see what gets output in the console.

34
00:02:39,000 --> 00:02:41,460
So it gets the solution output in the console.

35
00:02:41,760 --> 00:02:48,960
And we also saw within the example as well that we can create the function in a different format as

36
00:02:48,960 --> 00:02:49,170
well.

37
00:02:49,350 --> 00:02:51,360
And there's going to be more on this coming up.

38
00:02:51,690 --> 00:02:57,510
And we'll just call this multiplier two and then we're going to equal that to an anonymous function,

39
00:02:57,510 --> 00:03:06,660
taking in the two values, the two parameters to return back A times B or if we wanted to, we could

40
00:03:06,660 --> 00:03:08,370
write it within the same way as well.

41
00:03:08,580 --> 00:03:11,940
So all the block of the code that's inside is the same thing.

42
00:03:11,940 --> 00:03:17,370
It doesn't matter how you rate it a function expression, you do have to define it before you try to

43
00:03:17,370 --> 00:03:17,910
use it.

44
00:03:18,060 --> 00:03:20,490
Otherwise you're going to get an error in your code.

45
00:03:21,450 --> 00:03:24,300
So if I do try to do it like this, you're going to see it throws an error.

46
00:03:24,540 --> 00:03:31,710
So that means that we do need to have the function and we have to define it before we try to use it.

47
00:03:31,840 --> 00:03:37,530
So that's the real difference between the two, is that this one we can use at any point so we could

48
00:03:37,530 --> 00:03:41,940
even use it before we're defining the function and we're not going to throw any errors.

49
00:03:42,120 --> 00:03:45,380
And of course, we are going to be covering this in a little bit more detail coming up.

50
00:03:45,690 --> 00:03:47,100
So go ahead and try that out.

51
00:03:47,400 --> 00:03:50,790
And if you did the second option as well.

52
00:03:50,790 --> 00:03:55,200
So this is valid and an invalid format as well for a solution.
