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

Solution to "Create a Program with Math" with a spin.

Here is my solution but I added some additional information for more than seconds.

const secondsPerMin = 60;
const minutesPerHr = 60;
const hoursPerDay = 24;
const daysPerWk = 7;
const wksPerYr= 52;

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

const yearsAlive = 36;
//Added variables for a year in. minutes & seconds.
const yearToSecs = 31536000;
const yearToMins= 525600;
//My calculations in designated varibles.
const secondsAlive = yearToSecs * yearsAlive;
const minutesAlive = yearToMins * yearsAlive;
const hoursAlive = hoursPerDay * 365 * yearsAlive;

console.log(`I have been on this Earth for ${secondsAlive} seconds,${minutesAlive} minutes and ${hoursAlive} hours!`);

I welcome any notes , questions, or comments. Happy coding everyone!

1 Answer

Steven Parker
Steven Parker
230,995 Points

In keeping with the original program concept, it might be better to calculate the additional values instead of adding more constants:

const yearToSecs = secondsPerDay * 365;
const yearToMins = yearToSecs / secondsPerMin;

Thank you for the feedback. I have since gone back and updated. :)