1 00:00:00,000 --> 00:00:04,495 [MUSIC] 2 00:00:04,495 --> 00:00:07,950 This practice session covers basic JavaScript functions. 3 00:00:07,950 --> 00:00:11,870 It's a great followup to the fifth part of the JavaScript Basics course. 4 00:00:11,870 --> 00:00:15,470 If you haven't taken that yet, and find this practice session too difficult, 5 00:00:15,470 --> 00:00:18,620 then go through the first five parts of that course first. 6 00:00:18,620 --> 00:00:20,740 I've added a link in the teacher's notes below. 7 00:00:20,740 --> 00:00:23,760 For this practice session, you'll write four functions. 8 00:00:23,760 --> 00:00:27,380 Call those functions and output the results to the console. 9 00:00:27,380 --> 00:00:30,240 It's pretty simple but combines the basics of creating and 10 00:00:30,240 --> 00:00:31,760 using JavaScript functions. 11 00:00:31,760 --> 00:00:35,419 I've attached a workspace to this video which includes some starter files and 12 00:00:35,419 --> 00:00:36,200 instructions. 13 00:00:36,200 --> 00:00:39,978 Open up the workspace and open up the geometry.js file. 14 00:00:39,978 --> 00:00:43,810 You'll see six instructions listed as JavaScript comments. 15 00:00:43,810 --> 00:00:45,000 Here's what you should do. 16 00:00:45,000 --> 00:00:48,400 First attach the JavaScript file to the index.html file. 17 00:00:48,400 --> 00:00:52,610 After all, the program won't work at all unless the web page loads it. 18 00:00:52,610 --> 00:00:56,990 Next create a function that calculates the area of a rectangle. 19 00:00:56,990 --> 00:01:01,240 To calculate the area of a rectangle, you multiply the width by the height. 20 00:01:01,240 --> 00:01:04,010 So this function needs to accept two arguments, 21 00:01:04,010 --> 00:01:06,550 do some math, then return the results back. 22 00:01:06,550 --> 00:01:09,880 Then you'll create another function to calculate the volume 23 00:01:09,880 --> 00:01:11,860 of a rectangular prism. 24 00:01:11,860 --> 00:01:13,640 Also known as a box. 25 00:01:13,640 --> 00:01:16,970 For that, you multiply the width by the height by the length. 26 00:01:16,970 --> 00:01:18,480 This function should return the volume. 27 00:01:19,750 --> 00:01:23,385 Now the next two functions involve calculating the area of a circle and 28 00:01:23,385 --> 00:01:24,624 the volume of a sphere. 29 00:01:24,624 --> 00:01:29,691 These both require using the JavaScript math object to get the value of pi. 30 00:01:29,691 --> 00:01:33,564 And to use a method that lets you raise the number to a certain power. 31 00:01:33,564 --> 00:01:37,581 For example x to the second power or x squared. 32 00:01:37,581 --> 00:01:40,334 Now I didn't cover those in JavaScript basics course, so 33 00:01:40,334 --> 00:01:43,750 you'll need to do a bit of research to figure out how to use them. 34 00:01:43,750 --> 00:01:46,650 I've included links in the teacher's notes below. 35 00:01:46,650 --> 00:01:51,390 Okay so if you have the radius of a circle to calculate the area of a circle, 36 00:01:51,390 --> 00:01:54,310 you take pi times the radius squared. 37 00:01:54,310 --> 00:01:58,350 Squared is also refered as the second power or to the second power. 38 00:01:58,350 --> 00:02:02,210 So the function will receive a radius value and return the area. 39 00:02:02,210 --> 00:02:05,050 The last function will calculate the volume of a sphere. 40 00:02:05,050 --> 00:02:09,880 To do that you multiply four thirds by pi, by the radius cubed or 41 00:02:09,880 --> 00:02:11,670 the radius to the third power. 42 00:02:11,670 --> 00:02:15,860 Okay now finally you'll add four lines to log out 43 00:02:15,860 --> 00:02:19,390 the results of your function to the JavaScript console. 44 00:02:19,390 --> 00:02:23,205 It's not super exciting to look at, but this is what your output should look like, 45 00:02:23,205 --> 00:02:24,250 something like this. 46 00:02:24,250 --> 00:02:27,600 Now if you wanna do some quick study before tackling this practice session. 47 00:02:27,600 --> 00:02:29,032 In the teacher's notes look for 48 00:02:29,032 --> 00:02:31,530 links to videos that can help you solve this challenge. 49 00:02:31,530 --> 00:02:33,340 But if you're ready, go for it. 50 00:02:33,340 --> 00:02:36,640 Program your solution and I'll show you my solution in the next video.