Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Working With Numbers Doing Math

Omarwali Jones
Omarwali Jones
8,251 Points

Just so I'm clear... solution to secondsAlive

var secondsPerMin = 60;
var minsPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay;
document.write('<h1>There are ' + secondsPerDay + ' seconds in a day</h1>');
var yearsAlive = 26;
var secondsAlive = secondsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear * yearsAlive;
document.write('<h1> You\'ve been alive ' + secondsAlive + ' seconds');

so  60 * 60 * 24 * 7 * 52 * 26 = 817,869,600?
Jordan Gauthier
Jordan Gauthier
5,552 Points

Looks right to me, except I'm getting a value of 817,689,600. Probably just a simple typo.

3 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

You can write:

var secondsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;

instead of

var secondsAlive = secondsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear * yearsAlive;
Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Also one advice from me: declare variables separated by comma:

var secondsPerMin = 60,
      minsPerHour = 60,
      hoursPerDay = 24,
      daysPerWeek = 7,
      weeksPerYear = 52;

That is the solution I had :) Also agree with the declaration of multiple variables separated by commas. Keeps the code tidier and easier to read.

Omarwali Jones
Omarwali Jones
8,251 Points

I had no idea about the comma thing. Thanks for the help guys!

Abhijit Das
Abhijit Das
5,022 Points

Yup that's also nice info to me thanks.

Faraz Hasan
Faraz Hasan
4,596 Points

I just made a new variable of daysPerYear = 365; and did yearsAlive * daysPerYear * secondsPerDay;.

As someone who is awful at maths, should I not have done that? XD