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 Numbers Working with Numbers Create a Program with Math

This is my solution. Don't know if i got it right?

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPeryear = 52;

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay; console.log(There are ${secondsPerDay} seconds in a day.);

const daysPerYear = 365; const yearsAlive = 35;

const secondsAlive = secondsPerDay * daysPerYear * yearsAlive; console.log(I have been alive for more than ${secondsAlive} seconds!);

8 Answers

Steven Parker
Steven Parker
231,269 Points

I think the idea was to complete the calculation using only the variables created already in the video.

Hint: you defined "daysPerWeek " and "weeksPeryear" but have not used them yet.

Glad you pointed this out. I looked right past them. I also got different results with my idea vs the variables in the file.

If you ask 99% of everyone they will say there are 365 days in a non-leap year. So I rolled with that.

const yearsAlive = 10;
const daysAlive = yearsAlive * 365;
const secondsAlive = daysAlive * secondsPerDay;

"Been alive for more than 315360000 seconds!"

Using the variables there are 364 days in the year.

const secondsAlive = (secondsPerDay * (daysPerWeek * weeksPerYear)) * yearsAlive;

"Been alive for more than 314496000 seconds!"

I know we aren't looking for 100% precision in the project. But I thought it was novel and share worthy.

Molly Zalman
seal-mask
.a{fill-rule:evenodd;}techdegree
Molly Zalman
Full Stack JavaScript Techdegree Student 12,522 Points

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

const yearsAlive = 23; const secondsAlive = secsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear * yearsAlive; console.log(I've been alive for more than ${secondsAlive} seconds!);

This is what I got, and it isn't exactly correct but I'm just happy I made legitimate code!

shuai zhao
shuai zhao
2,122 Points

const secsPerMin = 60; const minsPerHr = 60; const hrsPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

const secondsPerDay = secsPerMin * minsPerHr * hrsPerDay; console.log(There are ${secondsPerDay} seconds in a day.);

const yearsAlive = secsPerMin * minsPerHr * hrsPerDay * daysPerWeek * weeksPerYear * 31; console.log(Ive been alive for more than [974937600] seconds!);

Rachael Carter
Rachael Carter
3,417 Points

We already defined 'secondsPerDay' earlier in the video, so I used that in my calculation:

const yearsAlive = 34; const secondsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;

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

I've been alive for more than 1069286400 seconds!

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay;

console.log(`There are ${secondsPerDay} seconds in a day.`);

const yearsAlive = 34;
const secondsAlive = secondsPerDay * yearsAlive;

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

"I've been alive for more than 2937600 seconds."

This is what I got for this.

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay; console.log(there are ${secondsPerDay} seconds in a day.);

const yearsAlive = 36; const secondsAlive = secondsPerDay * yearsAlive * daysPerWeek * weeksPerYear; console.log(I've been alive for more then ${secondsAlive} seconds.);

"there are 86400 seconds in a day." "I've been alive for more then 1132185600 seconds."

const secsPerMinute = 60;
const minPerHour = 60;
const hourPerDay= 24;
const dayPerWeek = 7;
const weekPerYear = 52;

const secsPerDay = secsPerMinute*minPerHour*hourPerDay;
console.log (`There are ${secsPerDay} seconds per day`);

const yearsAlive = 35;
console.log (`I've been alive for ${yearsAlive*secsPerDay*365} seconds.`);

I went a different way and did the calculation in the template literal. Worked like a charm.

Brandon Jones-Harris
Brandon Jones-Harris
6,713 Points

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52; const yearsAlive = 36;

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay; console.log(There are ${secondsPerDay} secoonds in a day.);

const secondsAlive = secsPerMin * minsPerHour * hoursPerDay * daysPerWeek * weeksPerYear* yearsAlive; console.log(I've been alive for more than ${secondsAlive} seconds!)