1 00:00:09,240 --> 00:00:14,580 Hi there, I hope you were able to finish this challenge that should be pretty easy. 2 00:00:14,730 --> 00:00:21,210 And in this video, I'm going to share with you the solution or actually one of the solutions, because 3 00:00:21,210 --> 00:00:24,690 there's never just one way of solving problems. 4 00:00:24,930 --> 00:00:27,420 So I'm just going to share with you my solution. 5 00:00:27,570 --> 00:00:35,640 And if you did it differently, we would love to see how you solved it so you can just share your solution 6 00:00:35,640 --> 00:00:37,020 in the Q&A section. 7 00:00:37,260 --> 00:00:44,820 OK, so going back to visuals to record, I just left these dates here, so I'm going to create two 8 00:00:44,820 --> 00:00:46,040 new variables. 9 00:00:46,050 --> 00:00:49,620 So the first one is going to be order date. 10 00:00:51,820 --> 00:01:00,550 Then we are going to create a new date object, and we know that we can pass either numeric arguments 11 00:01:00,550 --> 00:01:08,830 or string arguments if we just want to inform your month and date with pre numeric arguments. 12 00:01:08,860 --> 00:01:14,690 This is going to work so we can just do twenty, twenty then the month. 13 00:01:15,190 --> 00:01:20,550 Don't forget that March is not three because months they start from zero. 14 00:01:20,560 --> 00:01:22,900 So March is actually two. 15 00:01:24,250 --> 00:01:32,440 And the day is twenty six, if you want, you can do it like this, if you get confused with month starting 16 00:01:32,440 --> 00:01:36,510 from zero, you can just use the string argument. 17 00:01:36,790 --> 00:01:43,320 So then you can just type it like twenty, twenty three, twenty six. 18 00:01:43,330 --> 00:01:45,130 This is going to work as well. 19 00:01:45,340 --> 00:01:54,040 So now we have this date and we want to get the number of milliseconds since the apoc so we can calculate 20 00:01:54,040 --> 00:01:56,180 the interval between the two dates. 21 00:01:56,500 --> 00:02:03,550 So for this we are just going to use the get time method so that get time. 22 00:02:05,110 --> 00:02:11,860 Then we are just going to do the same thing for the delivery date. 23 00:02:13,870 --> 00:02:17,140 Which was April 2nd, so. 24 00:02:18,400 --> 00:02:19,030 April. 25 00:02:21,340 --> 00:02:28,240 Second, and now before we move ahead, let's just do consolidate that log, as we always do, and let's 26 00:02:28,240 --> 00:02:31,150 just try to send delivery date. 27 00:02:32,240 --> 00:02:34,280 Minus ordinate. 28 00:02:42,320 --> 00:02:48,890 So if we do this and refresh the page, as you can see, we're getting some number here and what is 29 00:02:48,890 --> 00:02:49,260 this? 30 00:02:49,460 --> 00:02:52,940 This is actually the difference in milliseconds. 31 00:02:53,180 --> 00:02:57,950 So this date has a number of milliseconds since the Abuk. 32 00:02:58,340 --> 00:03:04,680 This date has less milliseconds because it was prior to this second date. 33 00:03:04,970 --> 00:03:08,740 So between these two, we have a number of milliseconds. 34 00:03:09,110 --> 00:03:12,800 So how do we use it to calculate the dates? 35 00:03:14,650 --> 00:03:23,620 So we know that in one day, so let's go up to this table in one day, we have this amount of milliseconds. 36 00:03:24,100 --> 00:03:25,750 So if we do this. 37 00:03:26,720 --> 00:03:34,080 We can see that this product took seven days to be delivered, so this was actually pretty simple. 38 00:03:34,190 --> 00:03:42,200 But I want to share with you an even more simple solution because we don't need to use the get time. 39 00:03:42,470 --> 00:03:49,700 So let's not use the get time and let's just use the full object. 40 00:03:50,760 --> 00:03:52,710 To do a subtraction. 41 00:03:53,610 --> 00:03:57,840 So let's save this and let's refresh the page and see what happens. 42 00:03:58,050 --> 00:04:07,020 So, as you can see, JavaScript, just let us subtract that so we just subtract the delivery date from 43 00:04:07,020 --> 00:04:08,250 the order date. 44 00:04:08,250 --> 00:04:14,010 And JavaScript is just returning the same thing, which is the number of milliseconds between these 45 00:04:14,010 --> 00:04:14,460 dates. 46 00:04:14,680 --> 00:04:17,690 Then we just need to do what we did again. 47 00:04:18,000 --> 00:04:21,960 So I'm just going to get the number of milliseconds in one day. 48 00:04:23,680 --> 00:04:27,640 So I'm just going to create a new variable called lead time. 49 00:04:29,410 --> 00:04:38,380 Which is going to be this operation divided by the number of milliseconds in one day, so this time 50 00:04:38,380 --> 00:04:45,520 since we are not passing hours, we just have a round number, but we don't know if that's going to 51 00:04:45,520 --> 00:04:46,920 be the case every time. 52 00:04:46,930 --> 00:04:50,320 So it is better to just force. 53 00:04:53,970 --> 00:04:58,650 The round function, actually, not the round, but the floor function. 54 00:05:02,610 --> 00:05:04,290 So math that floor. 55 00:05:08,920 --> 00:05:14,110 And now, instead of sending it to the council, let's see what is the idea of that element. 56 00:05:18,270 --> 00:05:23,310 Let's select this, and this is the idea of the element delivery time. 57 00:05:23,610 --> 00:05:28,950 So again, document dot get Element by Bayada. 58 00:05:30,430 --> 00:05:35,050 This is the idea of that element, so in our TML. 59 00:05:37,130 --> 00:05:39,230 It's going to be the lead time. 60 00:05:40,760 --> 00:05:43,370 So saving this refreshing the page. 61 00:05:45,820 --> 00:05:51,770 And now we just solved this challenge, if you want to do an extra challenge, which would be cool. 62 00:05:51,790 --> 00:05:57,550 I'm not going to solve this one in video, but if you want to do it just to practice, you can do the 63 00:05:57,550 --> 00:05:58,180 opposite. 64 00:05:58,420 --> 00:06:04,200 So you can just get the order date and let's say you have the delivery time. 65 00:06:04,390 --> 00:06:12,880 So let's say your company takes, I don't know, 10 days to deliver the product, then try to calculate 66 00:06:13,120 --> 00:06:16,000 what is going to be the delivery date. 67 00:06:17,080 --> 00:06:20,800 So this is going to be very similar to what we just did. 68 00:06:21,670 --> 00:06:28,140 And it is going to be cool to practice a little more on working with date and time, so that was all. 69 00:06:28,150 --> 00:06:29,830 I hope you'll like this challenge. 70 00:06:29,830 --> 00:06:33,580 And in the next video, we are going to talk about time methods. 71 00:06:33,610 --> 00:06:34,360 I'll see you then.