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

What's wrong with my seconds alive code?

The code works when I copy someone else's "var secondsAlive" code from: var secondsAlive = 365 * secondsPerDay * yearsAlive; document.write('I have been alive ' + secondsAlive + ' seconds!');

However, I don't understand why the 365 is necessary or what is 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 = 39;
var secondsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;
document.write('I have been alive for ' + secondsAlive 'seconds.');

Thank you

2 Answers

Colin Bell
Colin Bell
29,679 Points

I'm guessing the challenge is looking for the explicit 365 number since daysPerWeek * weeksPerYear === 364.

Also, in your last line:

document.write('I have been alive for ' + secondsAlive + 'seconds.');
                                                    // ^ You forgot the second concatenator 

Thanks for the help, Colin. It actually wasn't for a challenge, so it didn't have to match. The instructor just asked us to try to figure it out. Turns out that once I added that missing concatenator it worked, without having to include 365. Glad to know I figured it out except for that syntax error.

Colin Bell
Colin Bell
29,679 Points

Ah, good deal. Syntax errors are the biggest pain because they're probably the most common, but the error messages they give aren't always exactly the most helpful. Especially when first starting out.