1
00:00:02,040 --> 00:00:04,880
Now because we are returning a value now,

2
00:00:04,880 --> 00:00:08,540
we're now a bit more independent when it comes to that

3
00:00:08,540 --> 00:00:10,822
total adult years variable, but there still,

4
00:00:10,822 --> 00:00:14,930
is another external variable,

5
00:00:14,930 --> 00:00:18,400
which we are using in calculate adult years.

6
00:00:18,400 --> 00:00:20,373
And that will be this age.

7
00:00:21,320 --> 00:00:23,520
This is still a variable, which we define

8
00:00:23,520 --> 00:00:27,560
outside of this function and then redefine here.

9
00:00:27,560 --> 00:00:32,280
And again, we typically want to avoid referencing

10
00:00:32,280 --> 00:00:35,920
and using such external variables here.

11
00:00:35,920 --> 00:00:38,660
Now, in case of the result, which we derived,

12
00:00:38,660 --> 00:00:42,410
we could solve the problem by returning.

13
00:00:42,410 --> 00:00:45,440
But what can we do in case of some

14
00:00:45,440 --> 00:00:48,260
input value which we're using?

15
00:00:48,260 --> 00:00:50,650
For this use case, we have a feature

16
00:00:50,650 --> 00:00:53,910
called function parameters.

17
00:00:53,910 --> 00:00:57,020
Function parameters are basically inputs we can

18
00:00:57,020 --> 00:00:59,500
accept in a function.

19
00:00:59,500 --> 00:01:02,370
And for those, we need to those parentheses here,

20
00:01:02,370 --> 00:01:04,819
directly after the function name

21
00:01:05,690 --> 00:01:08,330
Here, we can accept parameters

22
00:01:08,330 --> 00:01:12,360
and we can give those parameters any name of our choice

23
00:01:12,360 --> 00:01:14,353
and we can use as many as we need.

24
00:01:15,290 --> 00:01:17,700
Now here, I'm only interested in the age

25
00:01:17,700 --> 00:01:20,790
and to avoid name duplication,

26
00:01:20,790 --> 00:01:22,810
even though it's technically would be allowed,

27
00:01:22,810 --> 00:01:25,940
but to avoid confusion, I'll choose a different name here.

28
00:01:25,940 --> 00:01:28,133
I'll name it "User Age"

29
00:01:29,450 --> 00:01:32,223
It's like to finding a variable, but without

30
00:01:32,223 --> 00:01:35,290
the let keyword, but following the same

31
00:01:35,290 --> 00:01:39,150
naming conventions as we had them for variables.

32
00:01:39,150 --> 00:01:40,180
So this name is up to you,

33
00:01:40,180 --> 00:01:42,833
but should follow those rules and conventions.

34
00:01:43,770 --> 00:01:46,860
This is now a parameter of this function

35
00:01:46,860 --> 00:01:49,430
and inside of this function code.

36
00:01:49,430 --> 00:01:53,270
So between these curly braces, it acts as a variable

37
00:01:53,270 --> 00:01:56,920
that's only accessible inside of this function.

38
00:01:56,920 --> 00:01:58,640
So not outside of this function.

39
00:01:58,640 --> 00:02:01,740
We can't use user age here that won't work.

40
00:02:01,740 --> 00:02:04,583
It's only available inside of this function.

41
00:02:05,707 --> 00:02:07,720
And we cannot use that in our calculation

42
00:02:07,720 --> 00:02:10,223
instead of age we can use user age.

43
00:02:11,640 --> 00:02:14,130
Now, like that it would not work though.

44
00:02:14,130 --> 00:02:17,210
Instead, now that we added this parameter

45
00:02:17,210 --> 00:02:19,450
when we call the function,

46
00:02:19,450 --> 00:02:23,920
we have to pass a value for that parameter.

47
00:02:23,920 --> 00:02:26,040
And maybe you're already guessing it,

48
00:02:26,040 --> 00:02:29,060
that's what we do between the parentheses here,

49
00:02:29,060 --> 00:02:31,470
when we call a function.

50
00:02:31,470 --> 00:02:35,190
That's also what we're doing for alert already.

51
00:02:35,190 --> 00:02:39,570
Alert is a built in function provided by the browser that

52
00:02:39,570 --> 00:02:41,930
takes a parameter actually.

53
00:02:41,930 --> 00:02:44,660
And we're passing in a value for that parameter

54
00:02:44,660 --> 00:02:47,260
here in that case the value which we want to

55
00:02:47,260 --> 00:02:49,320
output in the alert.

56
00:02:49,320 --> 00:02:52,580
In case of our own function, we also want such a parameter

57
00:02:52,580 --> 00:02:54,780
and we want a parameter that we use in this

58
00:02:54,780 --> 00:02:58,453
mathematical calculation. So we want the age of the user.

59
00:02:59,690 --> 00:03:02,786
And therefore, here, when we call calculate adult years,

60
00:03:02,786 --> 00:03:06,300
we can, of course, just pass in a value,

61
00:03:06,300 --> 00:03:09,920
which we create on the fly, so to say.

62
00:03:09,920 --> 00:03:13,623
Or we use an existing variable, like age year.

63
00:03:14,680 --> 00:03:17,210
This age variable, which I created up here.

64
00:03:17,210 --> 00:03:19,490
I can use that down there as well,

65
00:03:19,490 --> 00:03:23,440
and pass that value into this function, when we execute

66
00:03:23,440 --> 00:03:25,050
this function.

67
00:03:25,050 --> 00:03:27,600
And here we also pass an age

68
00:03:27,600 --> 00:03:29,830
and that's the great thing about functions and

69
00:03:29,830 --> 00:03:31,900
why they are so useful.

70
00:03:31,900 --> 00:03:36,113
Especially if you do use parameters and return values.

71
00:03:37,010 --> 00:03:40,380
Now we define our general code once,

72
00:03:40,380 --> 00:03:43,220
but it's pretty flexible.

73
00:03:43,220 --> 00:03:47,610
We can call this function with different values for age,

74
00:03:47,610 --> 00:03:48,850
as we're doing it here.

75
00:03:48,850 --> 00:03:52,400
The value of age changes between these two function calls

76
00:03:52,400 --> 00:03:54,840
and we'll get back different results.

77
00:03:54,840 --> 00:03:59,840
Our general logic, our algorithm is always the same,

78
00:03:59,970 --> 00:04:03,180
but the concrete values change because we're using this

79
00:04:03,180 --> 00:04:04,743
parameter of value here.

80
00:04:06,070 --> 00:04:08,430
Now, of course you can only pass in a value

81
00:04:08,430 --> 00:04:11,950
for this parameter that makes sense for this function.

82
00:04:11,950 --> 00:04:15,260
So for example, passing in a text like, "Hi there"

83
00:04:15,260 --> 00:04:17,397
doesn't make a lot of sense.

84
00:04:17,397 --> 00:04:21,089
"Hi there" minus 18, which is the operation that

85
00:04:21,089 --> 00:04:24,480
would be performed, doesn't lead to anything useful

86
00:04:25,390 --> 00:04:28,500
But since you are the one writing your functions,

87
00:04:28,500 --> 00:04:31,270
and you're the one calling your functions,

88
00:04:31,270 --> 00:04:33,190
or if you're working in a team,

89
00:04:33,190 --> 00:04:36,320
you are passing on the information on how this function

90
00:04:36,320 --> 00:04:39,870
should be used, you of course know how to call it.

91
00:04:39,870 --> 00:04:43,110
And that, that in this case, we should pass in a number,

92
00:04:43,110 --> 00:04:46,693
for example, the number stored in our age variable.

93
00:04:47,820 --> 00:04:50,670
And with all of that, if we save this and it reloads,

94
00:04:50,670 --> 00:04:55,083
we again, get these alert boxes with 14 and 27.

95
00:04:56,310 --> 00:04:59,210
Now this function only needs one parameter.

96
00:04:59,210 --> 00:05:02,910
If we would need multiple parameters and other functions

97
00:05:02,910 --> 00:05:05,950
could need multiple parameters. For example,

98
00:05:05,950 --> 00:05:08,050
in an upcoming exercise for you,

99
00:05:08,050 --> 00:05:10,770
you will have a function with multiple parameters,

100
00:05:10,770 --> 00:05:13,680
then you can separate them with commas.

101
00:05:13,680 --> 00:05:16,930
So that would be another parameter here,

102
00:05:16,930 --> 00:05:20,100
separated by a comma. The names are always up to you,

103
00:05:20,100 --> 00:05:23,110
but you have to separate them with commas.

104
00:05:23,110 --> 00:05:24,540
Now, here, we don't need it,

105
00:05:24,540 --> 00:05:27,030
but it is something you should know because you will

106
00:05:27,030 --> 00:05:30,770
definitely also sometimes write functions that do need more

107
00:05:30,770 --> 00:05:31,943
than one parameter.

108
00:05:32,830 --> 00:05:33,870
And now with that,

109
00:05:33,870 --> 00:05:37,359
we are using all those amazing function features you should

110
00:05:37,359 --> 00:05:38,513
know about.

