Hey there, are you ready for a challenge and I know you are in this lesson, we're going to be creating
a miles to kilometers convertor, so we're going to need a few things.
We're going to need a prompt to ask the user for an input of the number of miles and then behind the
scenes using JavaScript and what you've learned in the earlier lessons.
We're going to take that and we're going to convert it into kilometers.
And the ratio to convert one mile to a one kilometer is one point six zero nine three four.
So I've got it here within the guide.
So you get bonus points for using a template literal to create the output of the message and output
that prompt value into the console.
And there's also a bonus, if you remember how to convert a data type into a number.
So taking that input, doing a conversion to a number, make sure that it is a no output, it do the
conversion, do the multiplication, output the message into the console, just like we've got here
within the example.
So go ahead, pause the video, try this out and I'll walk you through the solution.
Coming up first, create a variable in order to capture the input from the user so we can use a number
of miles as our variable and then creating a prompt in order to make the capture and asked the question
how many miles?
And this will serve as the variable that we're going to use going forward.
So when we add that in, of course, we get the prompt and we get that number being returned back.
So we're not doing anything with it yet.
We can log it out to the console if we want at this point and do number of miles.
And then also we can also see that when we get that input that this is going to be a string.
So we want to convert it into a number.
So the way to do that is to use the conversion type so we can take that variable and we can wrap it
with no and placed the variable within it.
And this will, in fact, turn it into a number and numeric data type and then we can use that in order
to do the multiplication.
So you see the difference between the black and the blue is actually do our full conversion.
So we're going to create another variable and we can call this one kilo value.
And this is where we're taking the number of miles and we're multiplying it by that magic number of
one point six zero nine three four.
We can console log that number out just to make sure that we're still on track before we try to use
it and output it into the console.
So now we're asking for how many miles?
We say five.
So we take an input that's string type.
We convert it into a number and then we multiply it by the value.
And this is going to return back the number of miles that is, or a number of kilometers that is equal
to five miles.
Now we're ready to create our message and this is our message output that we're going to use for the
user so we can give it another variable name and I'm going to call it message.
And we did say that we want to do the template literals.
And that was from one of the earlier lessons where we use the Batek.
So that's just above the tab side to the left of the one key on your keyboard on most keyboards.
And this is the dollar sign the curly brackets.
And then in here is where you place the variable that you want to use.
So in this case, I want to use the number of Meile and this is that value that was input and make sure
that you stay within those tactics, Miles, is equal to.
And then you can formulate your own response here, response message.
And then this is where we've got our chelo value that we're going to be returning back.
So returning back that chelo value to the user.
And then lastly, all we have to do is output it into the console so that we get our message and we
can complete the assignment.
So refresh asking how many miles it take six.
And we're going to see six miles is equal to nine point six, five, six kilometers.
Great job on completing this.
See in the next one.