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 trialJaclyn Mamuzich
2,298 PointsHello is there any way to verify if my code is correct? I'm not certain I've done the last part correctly.
var secondsPerMin = 60; var minsPerHour = 60; var hoursPerDay = 24; var daysPerWeek = 7; var weeksPerYear = 52; var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay; document.write("<h2>There are " + secondsPerDay + " seconds in a day</h2>"); var yearsAlive = 31; var secondsAlive = yearsAlive * weeksPerYear * daysPerWeek * hoursPerDay * minsPerHour * secondsPerDay * secondsPerMin; document.write(" <h2>I have been alive for " + secondsAlive + " seconds</h2>");
3 Answers
Allison Davis
12,698 PointsAh, I see. Math-wise, you've multiplied extra variables in the last part of the code. Because you already have a variable SecondsPerDay, you don't have to include some of the variables that you have, which shortens your code:
var secondsAlive = yearsAlive * weeksPerYear * daysPerWeek *secondsPerDay
Iain Simmons
Treehouse Moderator 32,305 PointsYou could just manually input the numbers into a calculator.
Or you can do a Google search for seconds in 52 weeks * 31
and it will give you the answer (if you just do seconds in 31 years
it will give the exact amount, calculating the leap years, etc.).
Allison Davis
12,698 PointsHi Jaclyn, Have you been using the JavaScript console in the Chrome Dev Tools? You can copy and paste your code right into the console and try it out. If you use Google chrome, just open the menu on the side (the three horizontal lines, and go to more tools, and then JavaScript console), or you can hit 'option' + 'command' + 'j' on a Mac. I'm not sure of the exact shortcut in Windows but I'm sure it's similar.
Spoiler alert: I pasted your code into my browser's console, and it runs! The only thing is that you'll want to add punctuation into your strings if you want the sentences to be punctuated properly when you see the result on the screen.
Jaclyn Mamuzich
2,298 PointsThanks for replying Allison. I was wondering if I did the math part correctly?