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 trialDerek Dorazio
1,004 PointsIs my code correct?
Just curious if my code is correct.
Please check out my work. I'm curious if I had made any mistakes.
I haven't checked out any other discussion questions as I didn't want to see other codes to make myself want to change my code.
Here is my snapshot. https://w.trhou.se/ljc6suqtj1
4 Answers
Steven Parker
231,236 PointsIt's fine as it is (good job! ), but since you already computed "secondsPerDay
", you could take advantage of that to make the final calculation a bit more concise:
var daysAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;
Also, while technically optional, it's good practice to always end a statement with a semicolon.
KRIS NIKOLAISEN
54,971 PointsOther than leap years looks good to me
Abdifatah Mohamed
5,289 Pointsvar secondsPerMin = 60; var minsPerHour = 60; var hoursPerDay = 24; var daysPerWeek = 7; var weeksPerYear = 52; var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay; document.write ('There are ' + secondsPerDay + ' seconds in a day'); var yearsAlive = 32; var socondsAlive = secondsPerMin * minsPerHour * hoursPerDay * yearsAlive; document.write('. I have been alive for more than ' + socondsAlive + ' seconds. '); //How about this guys? Am I correct? Please someone check it out ?
Steven Parker
231,236 PointsIt looks like your final calculation is missing some factors.
But always create a fresh question instead of posting a question as an "answer" to another one.
Abdifatah Mohamed
5,289 PointsOkay thanks.
Derek Dorazio
1,004 PointsDerek Dorazio
1,004 PointsOh yeah, you're completely right. I totally disregarded secondsPerDay. And yes I ended up looking at my post right after I posted it and noticed I didn't have a semicolon. Luckily someone pointed it out. :)