1
00:00:00,330 --> 00:00:05,670
Hey there, are you ready for a challenge and I know you are in this lesson, we're going to be creating

2
00:00:05,670 --> 00:00:09,330
a miles to kilometers convertor, so we're going to need a few things.

3
00:00:09,330 --> 00:00:15,630
We're going to need a prompt to ask the user for an input of the number of miles and then behind the

4
00:00:15,630 --> 00:00:19,610
scenes using JavaScript and what you've learned in the earlier lessons.

5
00:00:19,620 --> 00:00:22,500
We're going to take that and we're going to convert it into kilometers.

6
00:00:22,500 --> 00:00:29,330
And the ratio to convert one mile to a one kilometer is one point six zero nine three four.

7
00:00:29,340 --> 00:00:30,960
So I've got it here within the guide.

8
00:00:30,960 --> 00:00:37,050
So you get bonus points for using a template literal to create the output of the message and output

9
00:00:37,050 --> 00:00:39,690
that prompt value into the console.

10
00:00:39,700 --> 00:00:45,480
And there's also a bonus, if you remember how to convert a data type into a number.

11
00:00:45,490 --> 00:00:50,610
So taking that input, doing a conversion to a number, make sure that it is a no output, it do the

12
00:00:50,610 --> 00:00:55,560
conversion, do the multiplication, output the message into the console, just like we've got here

13
00:00:55,560 --> 00:00:56,570
within the example.

14
00:00:56,910 --> 00:01:01,620
So go ahead, pause the video, try this out and I'll walk you through the solution.

15
00:01:01,620 --> 00:01:07,860
Coming up first, create a variable in order to capture the input from the user so we can use a number

16
00:01:07,860 --> 00:01:14,070
of miles as our variable and then creating a prompt in order to make the capture and asked the question

17
00:01:14,070 --> 00:01:16,050
how many miles?

18
00:01:16,320 --> 00:01:19,370
And this will serve as the variable that we're going to use going forward.

19
00:01:19,620 --> 00:01:24,180
So when we add that in, of course, we get the prompt and we get that number being returned back.

20
00:01:24,360 --> 00:01:25,920
So we're not doing anything with it yet.

21
00:01:25,920 --> 00:01:31,110
We can log it out to the console if we want at this point and do number of miles.

22
00:01:31,320 --> 00:01:37,110
And then also we can also see that when we get that input that this is going to be a string.

23
00:01:37,110 --> 00:01:39,010
So we want to convert it into a number.

24
00:01:39,300 --> 00:01:45,780
So the way to do that is to use the conversion type so we can take that variable and we can wrap it

25
00:01:45,780 --> 00:01:49,200
with no and placed the variable within it.

26
00:01:49,320 --> 00:01:56,490
And this will, in fact, turn it into a number and numeric data type and then we can use that in order

27
00:01:56,490 --> 00:01:57,710
to do the multiplication.

28
00:01:57,930 --> 00:02:02,370
So you see the difference between the black and the blue is actually do our full conversion.

29
00:02:02,670 --> 00:02:07,050
So we're going to create another variable and we can call this one kilo value.

30
00:02:07,170 --> 00:02:13,380
And this is where we're taking the number of miles and we're multiplying it by that magic number of

31
00:02:13,380 --> 00:02:16,710
one point six zero nine three four.

32
00:02:16,740 --> 00:02:22,680
We can console log that number out just to make sure that we're still on track before we try to use

33
00:02:22,680 --> 00:02:24,290
it and output it into the console.

34
00:02:24,630 --> 00:02:26,490
So now we're asking for how many miles?

35
00:02:26,820 --> 00:02:27,840
We say five.

36
00:02:27,990 --> 00:02:30,810
So we take an input that's string type.

37
00:02:31,140 --> 00:02:35,220
We convert it into a number and then we multiply it by the value.

38
00:02:35,340 --> 00:02:41,340
And this is going to return back the number of miles that is, or a number of kilometers that is equal

39
00:02:41,340 --> 00:02:42,450
to five miles.

40
00:02:42,480 --> 00:02:46,800
Now we're ready to create our message and this is our message output that we're going to use for the

41
00:02:46,800 --> 00:02:50,250
user so we can give it another variable name and I'm going to call it message.

42
00:02:50,430 --> 00:02:53,400
And we did say that we want to do the template literals.

43
00:02:53,640 --> 00:02:57,590
And that was from one of the earlier lessons where we use the Batek.

44
00:02:57,640 --> 00:03:03,720
So that's just above the tab side to the left of the one key on your keyboard on most keyboards.

45
00:03:03,960 --> 00:03:06,990
And this is the dollar sign the curly brackets.

46
00:03:07,140 --> 00:03:10,420
And then in here is where you place the variable that you want to use.

47
00:03:10,440 --> 00:03:15,990
So in this case, I want to use the number of Meile and this is that value that was input and make sure

48
00:03:15,990 --> 00:03:20,220
that you stay within those tactics, Miles, is equal to.

49
00:03:20,220 --> 00:03:23,940
And then you can formulate your own response here, response message.

50
00:03:24,270 --> 00:03:27,980
And then this is where we've got our chelo value that we're going to be returning back.

51
00:03:28,260 --> 00:03:30,960
So returning back that chelo value to the user.

52
00:03:31,150 --> 00:03:37,050
And then lastly, all we have to do is output it into the console so that we get our message and we

53
00:03:37,050 --> 00:03:38,180
can complete the assignment.

54
00:03:38,430 --> 00:03:41,910
So refresh asking how many miles it take six.

55
00:03:42,210 --> 00:03:47,310
And we're going to see six miles is equal to nine point six, five, six kilometers.

56
00:03:47,850 --> 00:03:49,380
Great job on completing this.

57
00:03:49,530 --> 00:03:50,490
See in the next one.
