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 Numbers Working with Numbers Create a Program with Math

I realize now I did it needlessly long (haha) but this is what I got:

const secPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

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

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

Yeah this might be better to just have as notes for yourself! You should also use days per year instead of relying on weeks, it is more accurate. If you want to be even more accurate you would have to see which year you were born and account for leap years.

You could also make a yearsToSeconds function:

function yearsToSeconds(years) { return years*365*24*60*60; }

const secondsAlive = yearsToSeconds(32);

console.log(I've been alive for more than ${secondsAlive} seconds)

Happy coding!

7 Answers

Jonathan Tucker
seal-mask
.a{fill-rule:evenodd;}techdegree
Jonathan Tucker
Ubora | Web Development Techdegree Student 16,986 Points

I feel super old. LOL!! Here's my version.

const secsPerMin = 60;
const minsPerHour = 60;
const hoursPerDay = 24;
const daysPerWeek = 7;
const weeksPerYear = 52;
const daysPerYear = 365;
const myAge = 47;

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

const yearsAlive = secsPerMin * minsPerHour * hoursPerDay * daysPerYear * myAge;
console.log(`I've been alive for more than ${yearsAlive} seconds!`)

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

const yearsAlive = 99; // Your age const secsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive; console.log(I've been alive for more than ${secsAlive} seconds!);

olhahelena
olhahelena
6,731 Points

This is what I came up with. I used previously declared variables in this exercise.

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52; const yearsAlive = 26;

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

const secsAlive = (secsPerDay * 365) * yearsAlive; console.log(I've been alive for more than ${secsAlive} seconds!);

David Hilleke
David Hilleke
4,740 Points

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

It looks like I did it right if I've been alive for 10006387200 seconds. haha

const secsPerMin = 60; const minsPerHour =60; const hoursPerDay = 24; const DaysPerWeek = 7; const weeksPerYear = 52;

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

const yearsAlive = 32;

const secondsAlive = secsPerMin * minsPerHour * hoursPerDay * DaysPerWeek * weeksPerYear * yearsAlive

console.log (I've been alive for more than ${secondsAlive} seconds.);

Jason Rich
seal-mask
.a{fill-rule:evenodd;}techdegree
Jason Rich
Front End Web Development Techdegree Student 10,036 Points

Here's my version.

const secsPerMin = 60;
const minPerHour = 60;
const hoursPerDay = 24;
const daysPerWeek = 7;
const weeksPerYear = 52;
const daysPerYear = 365;

const yearsAlive = 48;

const secsAlive = (secsPerMin * minPerHour * hoursPerDay * daysPerYear * yearsAlive)
console.log(`I've been alive for more than ${secsAlive} seconds!`);

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

const daysPerYear = 365;

const secsPerYear = secsPerMin * minsPerHour * hoursPerDay * daysPerYear; console.log(There are ${secsPerYear} seconds in a year!)

const yearsAlive = 24; const secsAlive = secsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear * yearsAlive; console.log(I've been alive for ${secsAlive} seconds!);