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

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

I approached this with only adding one new variable. Is that good or bad?

I did this a lot differently to the rest of you guys. I didn't even think about storing other values into other variables to calculate this. I just went straight in to a new variable to calculate the values in the other variables that Dave created in the video. I am not sure if this is a bad thing or not? I mean, I can only see it being a bad thing if this program were to be future-proof, because it lacks other ways to get information due to other variables that don't exist. However, what do you guys think?

var secondsPerMin = 60;
var minsPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek = 7;
var weeksPerYear = 52;
var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay;
document.write('<p>There are ' + secondsPerDay + ' seconds in a day</p>');
var yearsAlive = 28;
var secondsPerYearsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;
document.write("<p>I've been alive for more than " + secondsPerYearsAlive + " seconds</p>");
Nasser Al Betar
Nasser Al Betar
3,711 Points

Hello Jamie, as I understand declaring variables allocates a portion of memory for them to be stored, so logically, the more variables declared, the more memory used.

Considering that the task was specific for the output required, there shouldn't be a concern about future-proofing, and you can see that your approach is a positive way of site optimization.

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Hi Nasser,

Ah I didn't know any if that great information you have provided! That is really good to know! My main concern was just that I felt that maybe since everyone else had a similar scope of practice that I wasn't on the same page/learning as everyone else. However thanks for that! :)

1 Answer

Victor Warner
Victor Warner
1,882 Points

I did the math wrong dviding first and incuding secondsperMin and minsPerHour. This answer helped me correct it. thank You.