Hi there, I hope you were able to finish this challenge that should be pretty easy.
And in this video, I'm going to share with you the solution or actually one of the solutions, because
there's never just one way of solving problems.
So I'm just going to share with you my solution.
And if you did it differently, we would love to see how you solved it so you can just share your solution
in the Q&A section.
OK, so going back to visuals to record, I just left these dates here, so I'm going to create two
new variables.
So the first one is going to be order date.
Then we are going to create a new date object, and we know that we can pass either numeric arguments
or string arguments if we just want to inform your month and date with pre numeric arguments.
This is going to work so we can just do twenty, twenty then the month.
Don't forget that March is not three because months they start from zero.
So March is actually two.
And the day is twenty six, if you want, you can do it like this, if you get confused with month starting
from zero, you can just use the string argument.
So then you can just type it like twenty, twenty three, twenty six.
This is going to work as well.
So now we have this date and we want to get the number of milliseconds since the apoc so we can calculate
the interval between the two dates.
So for this we are just going to use the get time method so that get time.
Then we are just going to do the same thing for the delivery date.
Which was April 2nd, so.
April.
Second, and now before we move ahead, let's just do consolidate that log, as we always do, and let's
just try to send delivery date.
Minus ordinate.
So if we do this and refresh the page, as you can see, we're getting some number here and what is
this?
This is actually the difference in milliseconds.
So this date has a number of milliseconds since the Abuk.
This date has less milliseconds because it was prior to this second date.
So between these two, we have a number of milliseconds.
So how do we use it to calculate the dates?
So we know that in one day, so let's go up to this table in one day, we have this amount of milliseconds.
So if we do this.
We can see that this product took seven days to be delivered, so this was actually pretty simple.
But I want to share with you an even more simple solution because we don't need to use the get time.
So let's not use the get time and let's just use the full object.
To do a subtraction.
So let's save this and let's refresh the page and see what happens.
So, as you can see, JavaScript, just let us subtract that so we just subtract the delivery date from
the order date.
And JavaScript is just returning the same thing, which is the number of milliseconds between these
dates.
Then we just need to do what we did again.
So I'm just going to get the number of milliseconds in one day.
So I'm just going to create a new variable called lead time.
Which is going to be this operation divided by the number of milliseconds in one day, so this time
since we are not passing hours, we just have a round number, but we don't know if that's going to
be the case every time.
So it is better to just force.
The round function, actually, not the round, but the floor function.
So math that floor.
And now, instead of sending it to the council, let's see what is the idea of that element.
Let's select this, and this is the idea of the element delivery time.
So again, document dot get Element by Bayada.
This is the idea of that element, so in our TML.
It's going to be the lead time.
So saving this refreshing the page.
And now we just solved this challenge, if you want to do an extra challenge, which would be cool.
I'm not going to solve this one in video, but if you want to do it just to practice, you can do the
opposite.
So you can just get the order date and let's say you have the delivery time.
So let's say your company takes, I don't know, 10 days to deliver the product, then try to calculate
what is going to be the delivery date.
So this is going to be very similar to what we just did.
And it is going to be cool to practice a little more on working with date and time, so that was all.
I hope you'll like this challenge.
And in the next video, we are going to talk about time methods.
I'll see you then.