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 trialJoseph Carrillo
2,137 PointsDid i get it right?
var secondsPerMin = 60;
var minPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var daysPerYear = 365;
var age = 31;
var secondsPerDay = secondsPerMin * minPerHour * hoursPerDay;
var aliveSeconds = secondsPerDay * daysPerYear * age;
document.write('There are ' + secondsPerDay + ' seconds in a day.');
document.write("<br /> <br />");
document.write('I have been alive for ' + aliveSeconds + ' seconds');
2 Answers
Joseph Wasden
20,407 PointsFrom what I can see, you only have one error. You are missing a ";" after the variable daysPerWeek. However, that won't prevent JavaScript from processing your code.
What exactly is the problem you are experiencing with this code?
Joseph Carrillo
2,137 PointsI am wondering if i am doing the calculation right. I believe i did it correctly.
Alissa Kuzina
5,835 PointsYour calculations are correct but you can perform it shorter.
var secondsPerMin = 60;
var minPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var daysPerYear = 365;
var age = 31;
var secondsPerDay = secondsPerMin * minPerHour * hoursPerDay;
var aliveSeconds = secondsPerMin * minPerHour * hoursPerDay * daysPerWeek * weeksPerYear * daysPerYear * age;
document.write('There are ' + secondsPerDay + ' seconds in a day. <br /> <br /> ');
document.write('I have been alive for ' + aliveSeconds + ' seconds');
Joseph Carrillo
2,137 PointsJoseph Carrillo
2,137 PointsI was supposed to calculate how many seconds i have been a live for.