Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.