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 JavaScript Basics (Retired) Working With Numbers Doing Math

Did i get it right?

var secondsPerMin = 60;

var minPerHour = 60;

var hoursPerDay = 24;

var daysPerWeek = 7;

var weeksPerYear = 52;

var daysPerYear = 365;

var age = 31;

var secondsPerDay = secondsPerMin * minPerHour * hoursPerDay;

var aliveSeconds = secondsPerDay * daysPerYear * age;

document.write('There are ' + secondsPerDay + ' seconds in a day.');

document.write("<br /> <br />");

document.write('I have been alive for ' + aliveSeconds + ' seconds');

I was supposed to calculate how many seconds i have been a live for.

2 Answers

Joseph Wasden
Joseph Wasden
20,406 Points

From what I can see, you only have one error. You are missing a ";" after the variable daysPerWeek. However, that won't prevent JavaScript from processing your code.

What exactly is the problem you are experiencing with this code?

I am wondering if i am doing the calculation right. I believe i did it correctly.

Alissa Kuzina
Alissa Kuzina
5,835 Points

Your calculations are correct but you can perform it shorter.

var secondsPerMin = 60;
var minPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var daysPerYear = 365;
var age = 31;

var secondsPerDay = secondsPerMin * minPerHour * hoursPerDay;
var aliveSeconds = secondsPerMin * minPerHour * hoursPerDay * daysPerWeek * weeksPerYear * daysPerYear * age;

document.write('There are ' + secondsPerDay + ' seconds in a day. <br /> <br /> ');

document.write('I have been alive for ' + aliveSeconds + ' seconds');