1
00:00:01,170 --> 00:00:07,020
OK so to make this age calculator I have a simple calc that each time l file was empty.

2
00:00:07,170 --> 00:00:10,640
I'll fill it in with my standard boiler plate.

3
00:00:10,770 --> 00:00:13,290
Let's put age calc as the title.

4
00:00:13,920 --> 00:00:17,220
Let's put a little H-1 again that says

5
00:00:20,340 --> 00:00:25,440
age calc solution and save it.

6
00:00:25,590 --> 00:00:31,010
Next we're going to make our javascript file which I will call calc.

7
00:00:32,580 --> 00:00:41,400
And I'm going to put a alert in there just to make sure it's connected and have my files connected OK

8
00:00:41,410 --> 00:00:41,800
.

9
00:00:42,120 --> 00:00:51,790
I go to my calc h t m l and I'll add in my script tag with source equals calc that genius.

10
00:00:52,160 --> 00:00:54,010
And there's one thing I want to show you here.

11
00:00:54,210 --> 00:01:00,220
If I save this and I go open it in the browser.

12
00:01:01,830 --> 00:01:04,310
Notice that I don't see my H-1 yet.

13
00:01:04,920 --> 00:01:10,100
So it tells me javascript alert connected but my H-1 hasn't loaded as soon as I click OK.

14
00:01:10,680 --> 00:01:12,950
Then it has loaded.

15
00:01:13,440 --> 00:01:20,030
And the reason that's happening is that I'm putting my script before this HDMI actually loads.

16
00:01:20,340 --> 00:01:26,460
So if I wanted that each one to be there I could put the script afterwards and we will talk a lot more

17
00:01:26,460 --> 00:01:28,190
about where you should put scripts.

18
00:01:28,200 --> 00:01:29,580
Some of them should go in the head.

19
00:01:29,580 --> 00:01:31,340
Some of them should go in the body.

20
00:01:31,470 --> 00:01:33,840
In this case I'm going to put this one down here in the body.

21
00:01:33,840 --> 00:01:39,180
It doesn't really make a big difference but it is worth knowing that if you put this script up top it's

22
00:01:39,180 --> 00:01:40,900
going to run first.

23
00:01:41,280 --> 00:01:42,620
So save this.

24
00:01:42,950 --> 00:01:44,850
Now let's go finish our logic here.

25
00:01:44,940 --> 00:01:52,020
So let's start by asking the user for their age so let's do var age because prompt.

26
00:01:52,800 --> 00:01:56,680
What is your age save.

27
00:01:56,970 --> 00:01:58,310
And then just to make sure it works.

28
00:01:58,320 --> 00:02:04,490
Let's do this to an alert just age and that's it.

29
00:02:04,490 --> 00:02:08,850
Then let's go back and open the file up.

30
00:02:08,850 --> 00:02:09,960
What is your age.

31
00:02:09,960 --> 00:02:10,890
10.

32
00:02:11,220 --> 00:02:13,320
And then just print out 10 an alert.

33
00:02:13,690 --> 00:02:14,490
OK.

34
00:02:14,820 --> 00:02:21,830
So next up we're now going to go and add the logic in to figure out how many days someone has spent

35
00:02:21,830 --> 00:02:23,760
a life.

36
00:02:23,850 --> 00:02:29,040
So I'm going to make a variable to store that in and I'm going to just call it days.

37
00:02:29,040 --> 00:02:39,460
So far days equals age times 365 days in a year and save that and then we'll do our alert here.

38
00:02:39,480 --> 00:02:41,630
So lower.

39
00:02:43,230 --> 00:03:03,040
And then we wanted to say age plus years is roughly plus the number days for us the word days.

40
00:03:03,480 --> 00:03:10,050
So this should say whatever the ages years is roughly whatever the days is days.

41
00:03:10,110 --> 00:03:12,300
So let's test that out.

42
00:03:12,930 --> 00:03:15,570
Refresh What is your age.

43
00:03:15,570 --> 00:03:22,670
Three three years is roughly one thousand ninety five days.

44
00:03:23,010 --> 00:03:27,380
One small adaptation we can make is that this doesn't account for leap years.

45
00:03:27,570 --> 00:03:30,240
So there is a leap year every four years.

46
00:03:30,330 --> 00:03:34,220
So the easiest way to include that is just to average that out.

47
00:03:34,350 --> 00:03:42,240
So instead of multiplying by 365 you multiply by 365 point to five a quarter of a year.

48
00:03:42,240 --> 00:03:45,940
Now if we try this again let's say that we are 50.

49
00:03:46,380 --> 00:03:53,720
We now get 50 years is roughly eighteen thousand two hundred sixty two point five days.

50
00:03:53,940 --> 00:03:54,310
OK.

51
00:03:54,420 --> 00:03:55,970
So that's all we had to do here.

52
00:03:56,160 --> 00:04:01,360
So the only real difference between this and the stocker problem is that we're doing some math beforehand
