1 00:00:00,270 --> 00:00:07,310 Similar to CSX JavaScript functions are most commonly placed in between the open and close had tags. 2 00:00:07,320 --> 00:00:13,320 The reason for this is because the head portion of an HMO page gets loaded before any other part of 3 00:00:13,320 --> 00:00:20,970 the HMO document so if you were to put your javascript code right before the closing body tag any javascript 4 00:00:20,970 --> 00:00:26,790 call is made to functions by your page as it loads will result in an error. 5 00:00:26,820 --> 00:00:33,120 Let's take a look at an example of a javascript function located in our head tag and called upon in 6 00:00:33,120 --> 00:00:34,350 our body. 7 00:00:34,350 --> 00:00:39,830 We won't get too much into the HDMI El here because by now most of this HCM El code should look familiar 8 00:00:41,140 --> 00:00:45,090 but this javascript code will calculate your age in dog years. 9 00:00:45,400 --> 00:00:50,760 A year of a person's life is equivalent to seven years of a dog's life. 10 00:00:50,860 --> 00:00:53,680 Let's preview this file before we take a look at the code 11 00:00:59,190 --> 00:01:03,560 as you can see we input our age in the first input field. 12 00:01:03,690 --> 00:01:11,470 I'll put one just for demonstration once we press calculate the javascript function is called it reads 13 00:01:11,470 --> 00:01:16,120 the value in the first input and multiplies it by 7. 14 00:01:16,120 --> 00:01:18,340 It places the result in the second input 15 00:01:25,590 --> 00:01:33,480 in the code we can see that the script for the javascript function is located in the head tag the function 16 00:01:33,480 --> 00:01:42,790 itself is called C years this function takes the value of the form element my age and multiplies it 17 00:01:42,850 --> 00:01:46,080 by 7. 18 00:01:46,100 --> 00:01:54,160 The result is then displayed in the form element dog age the entire function is activated when the user 19 00:01:54,160 --> 00:01:56,050 clicks the calculate button. 20 00:01:56,980 --> 00:02:03,730 This is when the javascript function is called we can see and on click event attached to the button 21 00:02:04,550 --> 00:02:07,650 we'll explore different events later in this course.