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

Alistair Lamberth
Alistair Lamberth
1,874 Points

Turns out I am at least 2505600 seconds old. Sound right to you guys?

This is how I did it... I am 29 years old. What do you guys reckon?

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 = 29 *secsPerMin * minsPerHour * hoursPerDay;

console.log(I have been alive for more than ${yearsAlive} seconds);

Lol i was wondering if i did wrong! XD

you have multiplied 29 by seconds per day so it means you have calculated the seconds in 29 days.

you can either multiply -> 29 * 365 which gives the number of days in 29 year since a year is 365 days and then multiply by secondsPerDay or just multiply all the variable made in the beginning (from secsPerMIn to weeksPerYear) and then multiply that with 29.

14 Answers

Joseph Hookham
Joseph Hookham
2,493 Points

No I think it should be around 1 billion (10 digits)

You've only multiplied by days (not years).

Use the 'secondsPerDay' that you did with Guill as a headstart.

Now you just multiply secondsPerDay X daysPerWeek X weeksPerYear X yearsAlive.

Here's mine:

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 = 33; const secsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;

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

ANSWER ON CONSOLE = 1,037,836,800

Austin Hinz
Austin Hinz
3,194 Points

Hello,

Here is my answer for someone that is 21:

//Variables that I will be using for the calculations
const secsPerMin = 60;
const minsPerHour = 60;
const hoursPerDay = 24;
const yearsMeAlive = 21;
const daysInYear = 365;

//Below are the variables created by combining above variables with math operators
const secondsPerDay = ( secsPerMin * minsPerHour * hoursPerDay );
const secondsAlive = ( secondsPerDay * daysInYear * yearsMeAlive );

//Below is what is the console.log output
I've been alive for more than 662256000 seconds! // 662_256_000 seconds

Hope this helps someone! Happy Coding :D
-Austin

Here's my solution to share, including what we went over in the video! Happy coding!

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

const secsPerDay = secsPerMin*minsPerHour*hoursPerDay;

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

const yearsAlive = 27
const secsAlive = secsPerDay*daysPerWeek*weeksPerYear*yearsAlive

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

Here is the Math:

const yearsAlive = secondsPerDay * daysPerWeek * weeksPerYear;

const secsAlive = yearsAlive * 40;

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

Answer: I've been alive for more than 1257984000 seconds!.

Seconds Per Day? No Minutes or Hours:-)

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

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay; const yearsAlive = X * weeksPerYear*daysPerWeek*hoursPerDay*minsPerHour*secsPerMin;

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

console.log (I have been alive for more than ${yearsAlive});

Hope i am helpful !

Here is my work to share

const secsPerMin = 60; const minsPerHour= 60; const hoursPerDay= 24; const daysPerWeek= 7; const weeksPerYear= 52; const daysPerYear= 365; const yearsAlive = 40;

const secondsPerDay= secsPerMin * minsPerHour * hoursPerDay;

const aliveInSeconds = yearsAlive * daysPerYear * secondsPerDay;

console.log(I have been alive for more than ${aliveInSeconds} seconds);

Happy coding :)

I'm shocked 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 yearsAlive = 36;

const secsAlive = yearsAlive * secondsPerDay; console.log(I've been alive for more than ${secsAlive} seconds!);

Ian Hawe
PLUS
Ian Hawe
Courses Plus Student 10,579 Points

const secsPerDay = secsPerMin * minsPerHour * hoursPerDay; const yearsAlive = secsPerMin * minsPerHour * hoursPerDay * daysPerYear * age;

console.log(There are ${secsPerDay} seconds in a day); console.log(I've been alive for more than ${yearsAlive} seconds!);

math.js:11 I've been alive for more than 883008000 seconds!

olhahelena
olhahelena
6,731 Points

This is what I came up with. I used previously declared variables in this exercise.

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

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

const secsAlive = (secsPerDay * 365) * yearsAlive; console.log(I've been alive for more than ${secsAlive} seconds!);

Console: I've been alive for more than 819936000 seconds!

Happy Coding!!

Kendall McCall
Kendall McCall
8,177 Points

Here is my attempt :)

const secPerMin = 60; const minPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

const secondsPerDay = secPerMin * minPerHour * hoursPerDay;

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

const yearsAlive = 24; const secsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive; console.log(I have been alive for more than ${secsAlive} seconds!);

I've been alive for more than 1949875200 seconds. (i think I got y'all beat?) where did all that time go?

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 secondsPerYear = secondsPerDay * daysPerWeek * weeksPerYear; const yearsAlive = 62; const x = yearsAlive * secondsPerYear

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

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 = 35;
const secondsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;
console.log(`I've been alive for more than ${secondsAlive} seconds!`);

document.querySelector('main').innerHTML = `<h1>I've been alive for more than ${secondsAlive} seconds!</h1>`;

Here's my solution, I like also practicing writing to the main!

I think it's a great idea to practice posting these to the main! I'm borrowing that idea from now on, thank you!

Brian Hough
Brian Hough
1,948 Points

Here's my solution! Turns out I've been alive for more than 788400000 seconds!

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 = 25;

const secsAlive = secondsPerDay * 365 * yearsAlive;

console.log(`I've been alive for more than ${secsAlive} seconds!`);
Hilary Scott
seal-mask
.a{fill-rule:evenodd;}techdegree
Hilary Scott
Full Stack JavaScript Techdegree Student 2,994 Points

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

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

const yearsAlive = 30, secondsAlive = secondsPerDay * daysPerWeek * weeksPerYear * yearsAlive;

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

I am 1415232000 seconds old.