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

Code Review - Javascript Math - How Many Seconds Have I Been Alive?

Hey, could anyone familiar with JS check my code is all good.. thanks!

const secspermin = 60;
const minperhour = 60;
const hourperday = 24;
const daysperweek = 7;
const weeksperyear = 52;

const secondsperday = secspermin * minperhour * hourperday;

const yearsalive = 26;

const secondsperyear = secondsperday * daysperweek * daysperweek * weeksperyear;

const secondsalive = secondsperyear / yearsalive;

console.log(` I've been alive for more than ${secondsalive} seconds.`);

1 Answer

Brandon White
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 Points

Your code looks good, Gavin (nice spacing and naming of variables; your math is just a bit off). In your secondsperyear variable you're multiplying daysperweek twice (you should only be multiplying by that variable once). Also you're dividing secondsperyear by yearsalive, when you should be multiplying secondsperyear by yearsalive.

The way your code is currently, it's saying that you're 98 days old (8,467,200 seconds). But if you make those changes, you should get more accurate results.

Thank you Brandon, silly mistakes to make, I guess this shows the importance of properly checking your own code before posting 😂