1 00:00:00,340 --> 00:00:02,371 All right, let's do some math with JavaScript. 2 00:00:02,371 --> 00:00:06,364 You'll build a simple program that can help you calculate the number of seconds 3 00:00:06,364 --> 00:00:09,420 in a day, hours in a week, or minutes in a year. 4 00:00:09,420 --> 00:00:13,657 You can code along with me by launching the workspace with this video. 5 00:00:13,657 --> 00:00:17,810 Open the math.js file located inside the js folder. 6 00:00:17,810 --> 00:00:20,281 The file is already linked to index.html. 7 00:00:23,647 --> 00:00:27,260 Let's start by creating a few variables that hold information about time. 8 00:00:28,270 --> 00:00:32,393 First, declare a variable named seconds per minute, 9 00:00:32,393 --> 00:00:36,437 that stores the number of seconds in a minute, 60. 10 00:00:36,437 --> 00:00:40,126 Then declare for more variables for other length of time. 11 00:00:40,126 --> 00:00:46,089 First minsPerHour = 60, 12 00:00:46,089 --> 00:00:53,046 then const hoursPerDay = 24, 13 00:00:53,046 --> 00:00:59,257 and const daysPerWeek = 7, 14 00:00:59,257 --> 00:01:06,223 and const weeksPerYear = 52. 15 00:01:06,223 --> 00:01:09,160 With this information, we can now start to do some math. 16 00:01:10,290 --> 00:01:14,860 Let's put a message to the console that lists the number of seconds in a day. 17 00:01:15,990 --> 00:01:18,940 I'll type a set of backticks to create a template literal 18 00:01:18,940 --> 00:01:23,355 that displays the message, there are dollar sign curly braces 19 00:01:23,355 --> 00:01:28,910 secondsPerDay seconds in a day. 20 00:01:32,050 --> 00:01:37,330 We can calculate the number of seconds in a day by multiplying the number of seconds 21 00:01:37,330 --> 00:01:43,030 in a minute by the number of minutes in an hour and the number of hours in a day. 22 00:01:44,810 --> 00:01:51,521 Above console.log, I'll declare the variable secondsPerDay and 23 00:01:51,521 --> 00:01:58,240 assign it secondsPerMinute times minsPerHour times hoursPerDay. 24 00:01:59,970 --> 00:02:03,770 Now the variable secondsPerDay holds the number of seconds in a day. 25 00:02:05,500 --> 00:02:10,040 As you can see in the console, there are 86,400 seconds in a day. 26 00:02:11,920 --> 00:02:13,990 Here's a small assignment for you. 27 00:02:13,990 --> 00:02:19,840 Add another variable named yearsAlive and assign it your age. 28 00:02:19,840 --> 00:02:25,472 Then print a second message to the console by adding another console.log statement. 29 00:02:25,472 --> 00:02:31,478 The message should say, I've been alive for more than x seconds. 30 00:02:38,461 --> 00:02:42,491 Replace the x with the number of seconds that have elapsed in all the years you've 31 00:02:42,491 --> 00:02:43,560 been alive. 32 00:02:43,560 --> 00:02:46,720 You'll need to do some multiplication of variables to get it done. 33 00:02:46,720 --> 00:02:47,730 So good luck, and 34 00:02:47,730 --> 00:02:51,250 when you're done, why don't you share your solution with other Treehouse students?