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

Marcus Alleyne
Marcus Alleyne
11,469 Points

Looks like I am 974,937,600 seconds old and counting lol. Was there a better way to do it?

Here's the code:

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay; console.log(There are ${secondsPerDay} seconds in a day);

const yearsAlive = 31; const secondsAlive = secsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear * yearsAlive console.log(I've been alive for more than ${secondsAlive} seconds);

1 Answer

Cameron Childres
Cameron Childres
11,820 Points

Nothing too crazy, but since you already defined secondsPerDay you don't need to multiply secsPerMin * minsPerHour * hoursPerDay again for secondsAlive. You could rewrite it as:

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay; 
console.log(`There are ${secondsPerDay} seconds in a day`);

const yearsAlive = 31;
const secondsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;
console.log(`I've been alive for more than ${secondsAlive} seconds`);

Sidenote -- check out the "markdown cheatsheet" linked under the comment box for code formatting on the forum, that way we can read it easier and you won't lose the backticks around template literals :)