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

Eddie Boscana
Eddie Boscana
6,966 Points

My Solution

// Constants representing conversion factors
const secsPerMin = 60;  // Number of seconds per minute
const minsPerHour = 60;  // Number of minutes per hour
const hoursPerDay = 24;  // Number of hours per day
const daysPerWeek = 7;  // Number of days per week
const weeksPerYear = 52;  // Number of weeks per year

// Calculating the number of seconds in a day
const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay;

// Logging the number of seconds in a day to the console
console.log(`There are ${secondsPerDay} seconds in a day.`);

// Assuming an age of 32 years
const yearsAlive = 32;

// Calculating the number of seconds alive 
// by multiplying seconds per day by the number of days in a week,
// then by the number of weeks in a year, and finally by the number of years alive
const secondsAlive =  secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;

// Logging the total number of seconds alive to the console
console.log(`I've been alive for more than ${secondsAlive} seconds.`);
Steven Parker
Steven Parker
231,248 Points

When posting code, use Markdown formatting to preserve the code's appearance and retain special symbols.
(click the link for a video tutorial) :point_up: