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 trialkalina edwards
5,454 PointsDid I do it right
var seconsdsPerMin = 60;
var minsPerHour = 60;
var hoursPerday = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var daysPerYear= 365;
var yearsAlive = 22;
var secondsAlive = seconsdsPerMin * minsPerHour * hoursPerday * daysPerYear * yearsAlive;
document.write('I have been alive for more than ' + secondsAlive + ' seconds');
MOD EDIT added code formatting for readability.
5 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Kalina,
Yes, your code is correct. It does the math and does display it to the browser screen.
Good Job.
Thomas Beaudry
29,084 PointsKalina, your syntax looks right however he asks you to put in your age and calculate it on your page, with actual numbers etc, best of luck!
kalina edwards
5,454 PointsYes, I put my age 22 (var years Alive = 22;) But I wondered did I calculate the seconds right? Thanks for commenting!
kalina edwards
5,454 PointsThanks for letting me know!
Ikuyasu Usui
36 PointsYou may want tor reuse a value for "secondsPerDay".
var daysPerYear= 365; var yearsAlive = 22; var secondsAlive = secondsPerDay daysPerYear yearsAlive;
Eduardo Calvachi
6,049 PointsGreat answer kalina edwards. Since we already calculated secondsPerDay
, We could also get secondsAlive
by multiplying it to the 365 days in a year and multiplying that by the years alive, like this:
var secondsAlive = secondsPerDay * 365 * yearsAlive;
kalina edwards
5,454 Pointskalina edwards
5,454 PointsOh okay thank you so much and also for the visual. I didnt know how to display the code in the editor. but thank you MOD
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsYou are very Welcome.
If you want to learn other tricks, there is a Markdown CheatSheet under the box where you type in your questions. Also, if you click on "edit question" on your original question here, you will see where I added the 3 backticks with the language name and closed off the block with another 3 backticks. This formats the code into a nicely formatted block.
I hope you enjoy your learning path here on Treehouse.