1
00:00:00,270 --> 00:00:04,860
All right, let's see how I'm going to solve this particular challenge.

2
00:00:05,380 --> 00:00:05,880
Okay.

3
00:00:05,880 --> 00:00:11,930
So first of all, it says that create a function to find the average of two numbers.

4
00:00:11,940 --> 00:00:18,590
So the first one gives me the name of the function that I'm supposed to use.

5
00:00:18,600 --> 00:00:19,410
So let's go.

6
00:00:19,410 --> 00:00:20,620
So come down here.

7
00:00:20,640 --> 00:00:23,340
My solution to this challenge is this.

8
00:00:24,000 --> 00:00:29,730
Well, the name of my function, let me say function.

9
00:00:29,730 --> 00:00:34,920
Just not fiction, but its function average.

10
00:00:35,590 --> 00:00:43,120
And then I would take in number one and then number two as my parameters.

11
00:00:43,270 --> 00:00:50,890
And in here I would declare const or let's let me select here because I want override the final result.

12
00:00:51,010 --> 00:00:55,450
So I would say my AVG average is equal to.

13
00:00:56,620 --> 00:01:02,970
Nam one plus num two divided by two.

14
00:01:02,980 --> 00:01:05,319
So I need to put them in.

15
00:01:06,760 --> 00:01:08,860
Parentheses like this one because of both.

16
00:01:09,220 --> 00:01:09,550
Right.

17
00:01:09,550 --> 00:01:11,380
But mine's meaning this one.

18
00:01:11,380 --> 00:01:12,190
Let me show you the board.

19
00:01:12,200 --> 00:01:12,910
My technique here.

20
00:01:12,940 --> 00:01:18,490
This is how we can multiply or add operations in a sequential manner.

21
00:01:18,550 --> 00:01:20,620
So you see that B means bracket.

22
00:01:20,620 --> 00:01:24,940
First, you need to handle the bracket first and then of means multiplication.

23
00:01:24,940 --> 00:01:27,730
If there is one, then you go ahead and division.

24
00:01:27,730 --> 00:01:27,990
Okay.

25
00:01:28,060 --> 00:01:30,640
That's why I put them inside like this one divided by two.

26
00:01:30,760 --> 00:01:33,640
Okay, so let's continue.

27
00:01:33,640 --> 00:01:36,130
So if I get that one, if I.

28
00:01:37,030 --> 00:01:41,680
Let me console.log as quickly from this function to avoid just returning the assignment variable like

29
00:01:41,680 --> 00:01:41,920
that.

30
00:01:41,920 --> 00:01:45,670
So let me console.log the results, the average.

31
00:01:46,270 --> 00:01:46,690
Okay.

32
00:01:46,690 --> 00:01:53,320
So if I save this function, let me return to be more precise because you want to write good code.

33
00:01:53,320 --> 00:01:55,480
Okay, let's return the average.

34
00:01:55,900 --> 00:01:56,410
Okay.

35
00:01:56,890 --> 00:02:06,280
So here, if I assigned the results equal to the average, then I pass in my two numbers.

36
00:02:06,280 --> 00:02:11,230
Let's say I want to find average between let's say two and four.

37
00:02:11,260 --> 00:02:15,730
What would be the answer to platform is six over two is going to be three.

38
00:02:15,910 --> 00:02:25,810
So if I console that log the the result like that, let's see in the console.

39
00:02:25,840 --> 00:02:26,890
Yes, indeed.

40
00:02:26,890 --> 00:02:28,510
We have three over here.

41
00:02:28,930 --> 00:02:29,230
Okay.

42
00:02:29,230 --> 00:02:36,130
What about if I provide, let's say something like seven, you see that I get 4.5.

43
00:02:36,130 --> 00:02:39,010
What about if I let's see, two point something like this one.

44
00:02:39,010 --> 00:02:40,570
Let's see the random numbers I get.

45
00:02:40,570 --> 00:02:42,460
We see that I get this one.

46
00:02:42,550 --> 00:02:45,640
And the question is, is that we need to run up to a whole number.

47
00:02:45,640 --> 00:02:48,970
So here we can use map that floor to floor this.

48
00:02:48,970 --> 00:02:56,530
So here I'll use map dot floor and then I'll pass in my average result.

49
00:02:56,830 --> 00:03:01,210
So this one, I will never get a decimal place, okay?

50
00:03:01,240 --> 00:03:07,630
Because this one have run up to some digit or better still, we can also convert this one to whole maybe

51
00:03:07,630 --> 00:03:11,800
two decimal places or one decimal places using to fix.

52
00:03:11,830 --> 00:03:13,630
Okay, so it's up to you.

53
00:03:13,630 --> 00:03:14,590
It's up to you.

54
00:03:14,800 --> 00:03:15,720
So here is I.

55
00:03:15,730 --> 00:03:16,150
Let's check.

56
00:03:16,150 --> 00:03:22,900
What about if I provide, let's say some the first one I want to add, let's say four and then the percent

57
00:03:22,900 --> 00:03:26,470
provide a string, let's say also as let's say two.

58
00:03:27,160 --> 00:03:31,860
Okay, let's see, we're going to be based on what's going through what would be the answer, right?

59
00:03:31,870 --> 00:03:34,330
We are trying to contact this a string.

60
00:03:34,330 --> 00:03:35,650
Right, a string.

61
00:03:35,680 --> 00:03:39,430
So we are trying to four plus two here.

62
00:03:39,460 --> 00:03:41,950
We give me something like this.

63
00:03:41,950 --> 00:03:50,320
According to what we've learned so far, going to be four and two because this course string concatenation.

64
00:03:50,620 --> 00:04:00,100
But if we divide by two, then it'll be undefined or null because how can we divide a number by a string?

65
00:04:00,100 --> 00:04:01,000
By a number.

66
00:04:01,690 --> 00:04:03,340
So let's see the result for this.

67
00:04:03,340 --> 00:04:08,230
So as a programmer, we need to avoid all these issues because we don't trust the user.

68
00:04:08,530 --> 00:04:12,130
So if I save it, you see that it's not a number.

69
00:04:12,340 --> 00:04:14,470
So how can we check for that?

70
00:04:14,470 --> 00:04:22,840
So here, let's say check, check if there are numbers.

71
00:04:24,010 --> 00:04:27,130
And I'm referring to they means my arguments.

72
00:04:27,130 --> 00:04:28,390
They are numbers.

73
00:04:29,520 --> 00:04:32,210
But not bombast, but instead numbers.

74
00:04:32,220 --> 00:04:36,740
So here we check and here you can use the number built in method.

75
00:04:36,750 --> 00:04:45,240
So let's say if again the we pass the the number and then you pass in the number.

76
00:04:45,300 --> 00:04:46,080
Number one.

77
00:04:47,270 --> 00:04:55,070
If indeed it's a number if and you're going to check for two conditions, if two of them are numbers,

78
00:04:55,070 --> 00:05:00,410
then you can go ahead and then display whatever you want or we can go ahead and do our logic.

79
00:05:00,620 --> 00:05:06,110
So here and the same number, then you pass in number two.

80
00:05:07,240 --> 00:05:07,900
Okay.

81
00:05:08,260 --> 00:05:14,800
If that's the case, then if it is true, then we can go ahead and then retain this.

82
00:05:15,190 --> 00:05:19,480
But we can reverse this one, making it as worth, not a number.

83
00:05:19,480 --> 00:05:23,740
So here I can copy this one and put it inside.

84
00:05:23,740 --> 00:05:33,610
Here else I can return a text and say that please provide.

85
00:05:35,010 --> 00:05:35,910
And number.

86
00:05:36,840 --> 00:05:38,850
So let's see, Nancy.

87
00:05:38,850 --> 00:05:39,440
I get what?

88
00:05:39,450 --> 00:05:44,130
Please provide a number, because what I did is not a number.

89
00:05:44,610 --> 00:05:49,050
What about if I make this one as ten and indeed one is string?

90
00:05:49,050 --> 00:05:50,040
Yes, indeed.

91
00:05:50,040 --> 00:05:51,900
We get plays, provide a number.

92
00:05:51,900 --> 00:05:53,580
So it's working.

93
00:05:53,620 --> 00:05:54,510
The next video.

94
00:05:54,540 --> 00:05:56,670
Let's have another coding challenge.

