Welcome to the Treehouse Community
Looking to learn something new?
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.');
Colin Bell29,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.