1 00:00:09,110 --> 00:00:13,110 Everyone, let's see the solution for exercise number two. 2 00:00:13,490 --> 00:00:18,090 So, number one, create a function to convert Celsius to Fahrenheit. 3 00:00:18,320 --> 00:00:22,160 So I'm just going to copy all this so I can use it in my code. 4 00:00:22,590 --> 00:00:24,470 So go into visual studio code. 5 00:00:24,800 --> 00:00:32,830 Like I said, I already created this new jass file, included the link at the bottom of this HTML file, 6 00:00:33,170 --> 00:00:36,360 and now I'm just going to solve the exercises. 7 00:00:37,220 --> 00:00:40,670 So first I'm going to create a function. 8 00:00:42,080 --> 00:00:44,820 And this is going to be the name of my function. 9 00:00:45,470 --> 00:00:50,210 This is the only thing I need than the formula is also going to be useful. 10 00:00:50,570 --> 00:00:51,620 So function. 11 00:00:52,610 --> 00:00:55,520 Let's just adjust the name so Celsius. 12 00:00:57,080 --> 00:00:57,620 To. 13 00:00:58,630 --> 00:01:07,210 Fahrenheit is going to be the name of my function, so open and close parentheses, open and close, 14 00:01:07,210 --> 00:01:11,530 curly braces inside here is going to be the code for our function. 15 00:01:12,040 --> 00:01:18,070 Now we are going to need an argument, which is going to be the Celsius temperature. 16 00:01:20,240 --> 00:01:30,980 So then we can just copy the formula, so we are going to create a variable called, say, Farenheit. 17 00:01:32,080 --> 00:01:36,280 Then here we are going to use the Celsius. 18 00:01:37,330 --> 00:01:45,880 Argument like this, so then we would have it calculated and then all we need to do is just returning 19 00:01:46,360 --> 00:01:53,500 the result, which is going to be the temperature and Fahrenheit, then we can do anything we want with 20 00:01:53,500 --> 00:01:54,310 this function. 21 00:01:54,700 --> 00:01:57,220 We can use it to send a valid to the console. 22 00:01:57,610 --> 00:01:58,780 We can use it to. 23 00:02:00,090 --> 00:02:08,520 Use it in another calculation or we can send to the boxes of our small file, which is what we are going 24 00:02:08,520 --> 00:02:09,660 to do now. 25 00:02:10,500 --> 00:02:17,040 So let's go back there to check the IDs of the boxes where we are going to get the Celsius temperature 26 00:02:17,040 --> 00:02:19,500 and where we need to place the results. 27 00:02:19,890 --> 00:02:27,060 So using the inspector, we can see that we have Celsius, one Celsius. 28 00:02:28,660 --> 00:02:36,400 Two and probably Celsius three and the same thing for the Fahrenheit boxes, so here we have far one. 29 00:02:37,470 --> 00:02:40,260 Then we have far, too. 30 00:02:41,300 --> 00:02:41,930 And. 31 00:02:43,030 --> 00:02:47,470 Far three, so these are the boxes that we're going to have to use. 32 00:02:47,800 --> 00:02:49,540 So let me just copy this. 33 00:02:52,290 --> 00:02:53,790 I'm just going to leave it here. 34 00:03:06,530 --> 00:03:13,520 All right, so the first thing we need to do here is create variables to get the Celsius temperature 35 00:03:13,730 --> 00:03:19,340 because we are going to have to convert it to a number before we use it in this function. 36 00:03:20,270 --> 00:03:25,340 So if we try to do everything in one line, this is going to be a bit messy. 37 00:03:25,700 --> 00:03:30,350 So let's just create a variable called Celsius one. 38 00:03:31,460 --> 00:03:36,800 And then this is going to be document that that element by ID. 39 00:03:37,700 --> 00:03:40,250 Then we can just use this. 40 00:03:41,620 --> 00:03:44,770 But instead of two is going to be Celsius one. 41 00:03:45,710 --> 00:03:51,890 And then we also want to convert it, we know that we don't have any decimal places, but since this 42 00:03:51,890 --> 00:03:57,220 is a temperature, it's possible that we have temperatures with decimal places. 43 00:03:57,650 --> 00:04:02,810 So let's do pass float, which is going to be safer. 44 00:04:04,000 --> 00:04:10,590 So pass floats, so now we have the temperature and this has been converted to a no. 45 00:04:10,600 --> 00:04:16,540 Just one thing I forgot, we still need to use the Internet age HTML property. 46 00:04:16,880 --> 00:04:18,580 So now this would be correct. 47 00:04:18,910 --> 00:04:21,820 Before we move on, let's just save this. 48 00:04:24,800 --> 00:04:26,310 And let's go to the concert. 49 00:04:26,330 --> 00:04:32,840 Let's try to get the Celsius one variable, as you can see, we were able to get the value here. 50 00:04:33,020 --> 00:04:37,440 So now we just have to use it as an argument for our function. 51 00:04:38,120 --> 00:04:41,870 So now we can just do document. 52 00:04:43,520 --> 00:04:45,740 Not get aliment by ID. 53 00:04:47,510 --> 00:04:49,760 Now it's going to be far. 54 00:04:50,710 --> 00:04:58,660 One, which is the element where we want to place the result so that in our age, tml and now what we 55 00:04:58,660 --> 00:05:02,020 are going to do here is just executing our function. 56 00:05:04,330 --> 00:05:05,830 And using this. 57 00:05:09,230 --> 00:05:16,460 Variable as an argument, so it is going to get this thirty eight, use it in the formula, return the 58 00:05:16,460 --> 00:05:23,660 value we want, so the value is going to be replaced here and it is going to go inside that element. 59 00:05:24,890 --> 00:05:30,010 Before moving on, let's refresh the page and see if this is working. 60 00:05:33,950 --> 00:05:36,370 So now we can see that this is working. 61 00:05:40,420 --> 00:05:48,820 Pretty cool now that we have a function, this is going to be really simple to repeat, we just spend 62 00:05:48,820 --> 00:05:56,470 a little time preparing the code, but now it's going to be as easy as just changing this to two and 63 00:05:56,470 --> 00:06:00,630 two here as well here as well. 64 00:06:03,510 --> 00:06:05,220 Another one for. 65 00:06:06,170 --> 00:06:08,300 The last element, so three. 66 00:06:09,640 --> 00:06:10,120 Three. 67 00:06:12,440 --> 00:06:14,270 Three and three. 68 00:06:15,820 --> 00:06:18,670 Saving this refreshing the page. 69 00:06:19,630 --> 00:06:24,970 We just used our function three times to make three temperature conversions. 70 00:06:26,820 --> 00:06:27,490 Pretty cool. 71 00:06:27,690 --> 00:06:34,560 No, to the array below is the classification of students in a contest, it is order from lowest to 72 00:06:34,560 --> 00:06:35,600 highest grade. 73 00:06:35,850 --> 00:06:41,670 So we need a place inside this element, the three best students. 74 00:06:42,010 --> 00:06:48,870 So if this is ordered from lowest to highest, we just need to get the last three students. 75 00:06:49,140 --> 00:06:51,440 How do we do this in JavaScript? 76 00:06:52,020 --> 00:06:53,730 First of all, let's copy this. 77 00:06:57,990 --> 00:06:59,550 So this is number two. 78 00:07:03,640 --> 00:07:05,630 Let's copy this variable. 79 00:07:05,870 --> 00:07:10,300 Now let's get the idea of that element that we need to place the result. 80 00:07:10,660 --> 00:07:13,060 So this is best student. 81 00:07:16,050 --> 00:07:19,260 OK, so we can just copy all this. 82 00:07:21,120 --> 00:07:29,310 And now let's replace the ID for our best students, so inside that element, we are going to place 83 00:07:29,310 --> 00:07:39,300 our array, but we are going to do a slicing so we know that we can do classification that slice and 84 00:07:39,300 --> 00:07:42,380 then we can use negative numbers. 85 00:07:42,750 --> 00:07:46,380 So if we do, minus one is just going to get the last. 86 00:07:46,590 --> 00:07:53,670 If we want the last three, we can just do minus three and then just omit the second value. 87 00:07:54,780 --> 00:07:57,630 You can include the comma or not if you don't want. 88 00:07:58,880 --> 00:08:06,280 I think in the example in the lesson, I just showed it like this, so let's see if this is working. 89 00:08:10,900 --> 00:08:12,400 Refreshing the page. 90 00:08:16,000 --> 00:08:22,950 And now we're seeing the last three students, which is exactly what we wanted. 91 00:08:26,340 --> 00:08:31,930 OK, number three, let's just copy this object so we can work with it. 92 00:08:32,520 --> 00:08:34,980 Let me go to Visual Studio Code. 93 00:08:36,020 --> 00:08:37,730 I'm just going to start. 94 00:08:39,730 --> 00:08:43,060 Number three here and just copy the objects. 95 00:08:43,090 --> 00:08:45,930 So now let's go back there to see what we need to do. 96 00:08:46,570 --> 00:08:49,400 So show the course title in the box below. 97 00:08:49,420 --> 00:08:50,820 This should be pretty simple. 98 00:08:50,830 --> 00:08:52,630 Let's just get the IDs. 99 00:08:53,200 --> 00:08:56,350 So we have the course title box. 100 00:08:58,470 --> 00:09:00,270 I'm just going to leave them here. 101 00:09:01,760 --> 00:09:07,220 We also have the main category element. 102 00:09:08,340 --> 00:09:10,440 So this is going to be four letter B. 103 00:09:11,650 --> 00:09:13,330 And four letter C. 104 00:09:14,940 --> 00:09:18,090 We have the reviews, Five Stars ID. 105 00:09:24,730 --> 00:09:31,030 OK, so first one, pretty simple to do, let's just use this one more time. 106 00:09:31,030 --> 00:09:36,610 I know we are repeating this method a lot of times, but this is good to practice. 107 00:09:36,850 --> 00:09:41,140 This is good to getting used to using this and typing faster. 108 00:09:42,100 --> 00:09:46,930 So first one, let's just replace it for the course title. 109 00:09:48,950 --> 00:09:53,060 And now we know that we can just do course that. 110 00:09:55,630 --> 00:10:01,600 If you want, you can use the Brace's notation by doing this, so Brace's. 111 00:10:03,870 --> 00:10:12,060 And then tidal, this is going to work the same way, but since our properties are following the variable 112 00:10:12,060 --> 00:10:20,190 naming rules, we can use the DOT notation, which not only is more simple, but it's actually more 113 00:10:20,220 --> 00:10:22,830 used by JavaScript programmers. 114 00:10:23,040 --> 00:10:26,340 So by doing this, let's see if this is right. 115 00:10:27,340 --> 00:10:32,830 Refreshing the page going down, we can see the title of the course here. 116 00:10:33,010 --> 00:10:36,130 Now the main category in the next box. 117 00:10:36,640 --> 00:10:39,340 So let's just get this. 118 00:10:41,560 --> 00:10:49,270 Now, the idea of the element is main category now this is going to be just as easy as the first one, 119 00:10:49,270 --> 00:10:51,670 we just need to go to the categories. 120 00:10:53,040 --> 00:10:58,560 And now we need to get the first element so the index is zero. 121 00:11:00,000 --> 00:11:01,200 By doing this. 122 00:11:03,140 --> 00:11:09,350 We are getting the main category, so let's see, we're just going to need to do some calculation. 123 00:11:09,360 --> 00:11:11,530 This is going to be easy as well. 124 00:11:12,870 --> 00:11:21,450 But for this, I would like to create a method, so I'm going to create a method for this object, which 125 00:11:21,450 --> 00:11:26,190 is going to be for the total number of reviews, because we have all this. 126 00:11:26,430 --> 00:11:30,580 Let's say we need to get the number of reviews for other things. 127 00:11:30,600 --> 00:11:33,800 Now, we need it for for this calculation. 128 00:11:34,080 --> 00:11:40,380 So instead of calculating again over and over again every time, I'm just going to create a method so 129 00:11:40,380 --> 00:11:41,340 we can do this. 130 00:11:42,970 --> 00:11:46,750 So the method is going to be named Toto. 131 00:11:52,870 --> 00:11:57,600 Reviews, so we are going to assign a function to it. 132 00:12:07,230 --> 00:12:10,620 And then we can just do this, that. 133 00:12:16,830 --> 00:12:18,310 Five star reviews. 134 00:12:18,990 --> 00:12:24,930 Actually, this is not going to work because these properties are not following the variable naming 135 00:12:24,930 --> 00:12:28,110 rules, so we cannot use the dot notation. 136 00:12:28,260 --> 00:12:30,210 So we have to do it like this. 137 00:12:31,710 --> 00:12:35,190 With the braces and quotation marks. 138 00:12:36,340 --> 00:12:41,920 OK, now this should be good, so we need to get five star reviews. 139 00:12:45,590 --> 00:12:47,450 All the four star reviews. 140 00:12:50,240 --> 00:12:52,940 Three stars, two stars and one stars. 141 00:12:55,720 --> 00:12:56,920 So one. 142 00:13:02,660 --> 00:13:03,230 Three. 143 00:13:04,350 --> 00:13:12,240 Four and five, so now every time we need to use the total number of reviews for anything, we just 144 00:13:12,240 --> 00:13:14,690 have a method that is going to do this for us. 145 00:13:15,060 --> 00:13:16,770 So let's just return this. 146 00:13:21,890 --> 00:13:29,300 And now to see if this is working before moving ahead, we can print it to the council so we can use 147 00:13:29,300 --> 00:13:30,010 course. 148 00:13:35,230 --> 00:13:40,540 Total reviews, open and close parentheses, because this is a method. 149 00:13:42,820 --> 00:13:44,920 So let's see if this is working. 150 00:13:47,000 --> 00:13:54,740 Refreshing the page going to the con so we can see that we have the total number of reviews really good. 151 00:14:00,960 --> 00:14:03,540 Now, let's just copy this. 152 00:14:09,030 --> 00:14:10,270 Let's get the idea. 153 00:14:10,290 --> 00:14:12,000 So the idea is. 154 00:14:13,250 --> 00:14:21,110 With these five stars where we need to place the result and inside this elements, we are just going 155 00:14:21,110 --> 00:14:21,620 to do. 156 00:14:25,370 --> 00:14:26,030 Of course. 157 00:14:30,180 --> 00:14:37,200 Then we're going to get the number of five star reviews, so we need to use Brace's because of how the 158 00:14:37,200 --> 00:14:41,100 property was named and then we just need to. 159 00:14:43,940 --> 00:14:46,760 Divided by the total reviews. 160 00:14:51,080 --> 00:14:52,820 OK, so by doing this. 161 00:14:56,100 --> 00:15:02,450 This is going to be part of what we need to do, so let's just save this just to see if this is working. 162 00:15:04,580 --> 00:15:10,970 OK, this is working, but now we just need to multiply it by a hundred so we can get the percentage 163 00:15:10,970 --> 00:15:19,580 because now we have a number from zero to one and we need to show it like 75 percent, 20 percent of 164 00:15:19,580 --> 00:15:20,560 stuff like this. 165 00:15:20,840 --> 00:15:21,860 So we just. 166 00:15:23,120 --> 00:15:30,500 Need to apply a little bit more calculation and formatting, so for this, I think it's better to create 167 00:15:30,500 --> 00:15:33,070 a variable, do it separately. 168 00:15:33,350 --> 00:15:36,620 So I'm going to create a variable called percentage. 169 00:15:38,030 --> 00:15:40,160 Then let's get all this. 170 00:15:43,750 --> 00:15:45,370 And replace it here. 171 00:15:46,840 --> 00:15:48,760 And down here, we can just. 172 00:15:50,620 --> 00:15:57,400 Use this variable, so now we can do the rest of the stuff we need to do, so now we can just multiply 173 00:15:57,400 --> 00:15:58,750 it by 100. 174 00:16:00,030 --> 00:16:04,740 Then we can just enclose everything inside parentheses. 175 00:16:06,580 --> 00:16:14,080 And before going ahead, let's see what happened, let's save this, just see if this is working. 176 00:16:14,240 --> 00:16:20,680 So I prefer to do this step by step, go back there, see if this is working before I move ahead. 177 00:16:22,810 --> 00:16:28,510 So refreshing the page, let's go down here, we can see that. 178 00:16:31,310 --> 00:16:37,870 This is now closer to what we need now we just need to round this number to zero decimal places. 179 00:16:38,120 --> 00:16:40,430 We know that we can do this by just. 180 00:16:42,810 --> 00:16:45,900 Applying the round function so round. 181 00:16:48,300 --> 00:16:54,540 Actually, I just forgot that round is a method of the math. 182 00:16:55,350 --> 00:16:58,980 Object, so now it should be right. 183 00:17:02,130 --> 00:17:03,900 Now we have seven, 75, five. 184 00:17:04,970 --> 00:17:07,470 Which is good if you want to make this better. 185 00:17:07,490 --> 00:17:14,630 You can even get this and convert it into a string, so to string. 186 00:17:15,580 --> 00:17:18,340 And then you can concatenated we have a. 187 00:17:19,530 --> 00:17:20,970 Percentage sign. 188 00:17:21,270 --> 00:17:22,470 So by doing this. 189 00:17:25,710 --> 00:17:33,960 Now we can see that seventy five percent of our reviews are five star reviews, pretty cool. 190 00:17:33,960 --> 00:17:34,800 This is done. 191 00:17:35,310 --> 00:17:38,840 Now, this video is almost exceeding the limit. 192 00:17:38,850 --> 00:17:40,380 So I'm going to stop here. 193 00:17:40,380 --> 00:17:42,810 And in the next video, I'm going to solve a number. 194 00:17:43,470 --> 00:17:44,280 I'll see you then.