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 trialOmarwali Jones
8,251 PointsJust 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?
3 Answers
Sergey Podgornyy
20,660 PointsYou can write:
var secondsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;
instead of
var secondsAlive = secondsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear * yearsAlive;
Sergey Podgornyy
20,660 PointsAlso one advice from me: declare variables separated by comma:
var secondsPerMin = 60,
minsPerHour = 60,
hoursPerDay = 24,
daysPerWeek = 7,
weeksPerYear = 52;
Fidel Severino
3,514 PointsThat 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
8,251 PointsI had no idea about the comma thing. Thanks for the help guys!
Abhijit Das
5,022 PointsYup that's also nice info to me thanks.
Faraz Hasan
4,596 PointsI 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
Jordan Gauthier
5,552 PointsJordan Gauthier
5,552 PointsLooks right to me, except I'm getting a value of 817,689,600. Probably just a simple typo.