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

I need help with the 'Seconds alive' exercise. Can you show me where I went wrong with my code?

var 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 = 31; var secondsAlive = secondsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear * yearsAlive; document.write('I have been alive for ' + secondsAlive +' seconds');

4 Answers

Jesus Bayona
Jesus Bayona
4,937 Points

Your code seems to be working, A-A-Ron. Although, you could've shortened it since you've already figured out secondsPerDay and didn't need to work it out in the final equation again. Good job!

Frantisek Mede
Frantisek Mede
4,749 Points

var secondsPerMin = 60;

var minsPerHours = 60;

var hoursPerDay = 24;

var daysPerWeek = 7;

var weeksPerYear = 52;

var secondsPerDay = secondsPerMin * minsPerHours * hoursPerDay;

document.write('There are ' + secondsPerDay + ' seconds in a day');

var myAge = 30

var yearsAlive = secondsPerDay * daysPerWeek * weeksPerYear * myAge;

document.write('I have been alive ' + yearsAlive + ' seconds');

is it ok??

Himanshu Chopra
Himanshu Chopra
3,055 Points

Hello Aaron was working on the same challenge today. you can try this.

var secondsPerMinute = 60;
var minutesPerHour = 60;
var hourPerDay = 24;
var daysPerYear = 365;
var myAge = 25;

var secondsAlive = secondsPerMinute * minutesPerHour * hourPerDay * daysPerYear * myAge; 

document.write('<h3> I have been alive from ' + secondsAlive + ' seconds </h3>');

and If you want then I can explain this to you. would love to help you mate, let me know :)

Farrah Dickerson
Farrah Dickerson
10,173 Points

Hi, Aaron! I see that the code you wrote is, indeed, working. Other than a tweak or two for punctuation and spacing consistency, it looks fine. Did you have a specific concern that you were referring to?