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

derek hunter
derek hunter
2,265 Points

was this good?

const age= 37
const secspermin = 60
const minsperhour= 60
const hoursperday= 24
const daysperweek=7
const weeksperyear=52
const daysperyear = 365

const secondsperday = secspermin * minsperhour * hoursperday;
console.log (` there are ${secondsperday} seconds in a day.`);

const yearsAlive= secspermin * minsperhour *hoursperday * daysperyear * age;
console.log (`I've been alive for more than ${yearsAlive} seconds !`);
Caleb Kemp
Caleb Kemp
12,676 Points

I tested it and it produced result as intended, however, there are 2-3 things I think could potentially be improved.

-1. As a best practice, your const variables should have semicolons(;) after them. Such that

const dayperweek = 7

should look like

const dayperweek = 7;

-2. Usually it is a good idea to use coding conventions when possible. One of the conventions of Javascript is to name the variables using camel case. So, using camel case this...

const weeksperyear = 60;

would have looked like

const weeksPerYear = 60;

-3. It seemed to me, since you had already calculated and stored secondsPerDay, it might have made sense to use that in your yearsAlive calculation, but just a thought. So that

const yearsAlive= secsPerMin * minsPerHour *hoursPerDay * daysPerYear * age;

would have looked like

const yearsAlive= secondsPerDay * daysPerYear * age;

Way to keep coding :smile: