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 trialAdrian Orive
721 PointsI 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
);
7 Answers
Jonathan Tucker
Ubora | Web Development Techdegree Student 16,987 PointsI 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!`)
Brett Burgess
2,511 Pointsconst 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
6,731 PointsThis 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
4,741 Pointsconst yearsAlive = 31;
console.log(I've been alive for more than ${secondsPerDay * 365 * yearsAlive} seconds!
);
Tanya Townsend
11,692 PointsIt 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
Front End Web Development Techdegree Student 10,048 PointsHere'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!`);
Avery Blake
7,419 Pointsconst 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!
);
Georg Ekeberg
5,702 PointsGeorg Ekeberg
5,702 PointsYeah 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!