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 trialKimberly Dolcin
4,369 PointsI am trying to find out the total number of seconds I have been alive in all the years I have been alive, is this correc
var secondsPerMin= 60;
var minsPerHour=60;
var hoursPerDay = 24;
var hoursPerWeek = 7;
var weeksPerYear = 52;
var secondsPerDay = secondsPerMin *minsPerHour * hoursPerDay;
document.write("There are" + secondsPerDay + "seconds in a day");
var yearsAlive = secondsPerDay * 22
4 Answers
Kevin Williams
Courses Plus Student 2,186 Pointsvar secondsPerMin = 60;
var minsPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear= 52;
var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay;
var secondsPerYear = secondsPerMin * minsPerHour * hoursPerDay * 365;
document.write("There are " + secondsPerDay + " seconds in a day ");
var yearsAlive = 26; /*Years I have been alive*/
document.write("I have been alive for" + yearsAlive * secondsPerYear + " seconds.");
I know this may be late, but this is how I calculated it.
What you need to do is figure out how many seconds are in a year. For my math I used only the mins, hours, and days. Then I took that amount and multiplied it by 365. After that I created a variable with the amount of seconds that are in a year (secondsPerYear) and got that total as you can see in the code. Doing this allowed me to multiply yearsAlive with secondsPerYear and gave me an estimate of how long I have been alive from 1992 to 2018 which is 819936000 seconds. I hope this helped.
Kimberly Dolcin
4,369 PointsNo, it is yearsAlive, i got this proble from the 4th checkpoint in the JavaScript Basics course entitled "JavaScript Basics" can you explain why i have to multiply days per year?
Steven Parker
231,271 PointsYou said you wanted to determine "the total number of seconds I have been alive". So it would make sense to call that "secondsAlive". Apparently, "yearsAlive" in your case is 22.
So if you multiply 22 by "secondsPerDay" the resulting value would the number of seconds in 22 days (1,900,800). Then if you multiply again by days per year you will get the number of seconds in 22 years (164,229,120,000).
Chanraksar Wat
1,251 PointsSo I've been trying to do this step by step and came up with code. Please let me know if I do it right. '''html <p> https://teamtreehouse.com/workspaces/38306242#</p> ''' Age: 25 Answer I got: 786240000 seconds
Gancho Iliev
10,264 PointsI've done it this way:
var secondPerMin = 60;
var minsPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var secondsPerDay = secondPerMin * minsPerHour * hoursPerDay;
var yearsAlive = 365 * secondsPerDay * 26;
document.write('There are ' + secondsPerDay + ' seconds in a day.');
document.write(' I\'ve been alive for ' + yearsAlive + ' seconds.');
Is it wrong? Thanks
Kimberly Dolcin
4,369 PointsKimberly Dolcin
4,369 Pointsthank you!!