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 trialNeil Martin Orbase
4,137 PointsNot the quickest in math, but was wondering if this was the correct calculation and code to find num of seconds in years
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;
console.log(`I've been alive for more than ${yearsAlive * weeksPerYear * daysPerWeek * secondsPerDay} seconds!`);
7 Answers
Steven Parker
231,248 PointsExactly right, good job!
Jodi Engel
4,726 Pointsconst secsPerMin = 60;
const minsPerHour = 60;
const hoursPerDay = 24;
const daysPerWeek = 7;
const weeksPerYear = 52;
const secsPerDay = secsPerMin * minsPerHour * hoursPerDay;
console.log(`There are ${secsPerDay} seconds in a day`);
const yearsAlive = 45;
const secsAlive = yearsAlive * weeksPerYear * daysPerWeek * secsPerDay;
console.log(`I've been alive for more than ${secsAlive} seconds!`);
benoit koch
3,875 PointsThis is what i came up with.
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.
);
let yearsAlive;
console.log(I've been alive for more than ${+86400 * +7 * +52 * +31} seconds!
);
Steven Parker
231,248 PointsI think the idea was to use the constants and not replicate the literal values. Also, what are the "+" symbols for?
benoit koch
3,875 PointsAll good :) Oh, i think it was a mistake on my part, i was thinking for some reason that the system would read it as a string, so i added some precautions but i don't think that would of affected the conclusion. + is the quick form of parseInt. "The parseInt() function parses a string and returns an integer."
Steven Parker
231,248 PointsNo danger of digits being interpreted as a string. Also, be aware that "+" isn't quite an exact replacement for "parseInt". One big difference is how they handle an empty string.
Chris Conwell
2,268 PointsYour script will output as a string and how the total if you use template literals ();
console.log(
I've been alive for more than ${+86400 * +7 * +52 * +31} seconds!
);
benoit koch
3,875 PointsThanks for letting me know, really appreciate the advice! :)
Fabio Dolcemascolo
Front End Web Development Techdegree Student 6,435 Pointsconst secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52; const yearsAlive = 39;
const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay;
console.log(There are ${secondsPerDay} seconds in a day.
);
const secondsPerWeek = secondsPerDay * daysPerWeek;
console.log(There are ${secondsPerWeek} seconds in a week.
);
const secondsPerYear = secondsPerWeek * weeksPerYear;
console.log(There are ${secondsPerYear} seconds in a year.
);
const secondsAlive = secondsPerYear * yearsAlive;
console.log(I've been alive for more than ${secondsAlive} seconds!
);
Terfa Nomhwange
2,230 Pointsconst 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 = 36;
const secondsPerYear = secondsPerDay * daysPerWeek* weeksPerYear
console.log(I've been alive for more than ${secondsPerYear} seconds
);