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

Bee Priola
Bee Priola
3,922 Points

What was I do wrong?

var secondsPerMin = 60; var minsPerHour = 60; var hoursPerDay = 24; var daysPerWeek = 7; var weeksPerYear = 52; var daysPerYear = 365; var age = 32; var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay; document.write('There are' + secondsPerDay + ' seconds in a day');

var yearsAlive = secondsPerDay * daysPerYear * age;

document.write ('I've been alive' + yearsAlive + 'seconds');

Try this .. var minutes = 60; var seconds = 60; var hours = 24; var year = 365; var secondsInAYear = minutes*seconds*hours*year; var age = 26; var livingSeconds = secondsInAYear*age; var message = "<h1>There are " + secondsInAYear + " seconds in a year."; message += "I have been alive for " + livingSeconds + " seconds. </h1>"; document.write(message);

3 Answers

You need to either escape -- I've -- or use double quotes to wrap the whole statement

Option 1:

document.write ('I\'ve been alive' + yearsAlive + 'seconds');

option 2:

document.write ("I've been alive'" + yearsAlive + "'seconds");
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi! I've changed your comment to an answer to both mark the question as answered in the forums and to allow for voting/best answer assignment. Thanks for your help in the Community! :sparkles:

Kabolobari Benakole
Kabolobari Benakole
Courses Plus Student 14,278 Points

I upvoted Helmut, because when I checked your code, I noticed the problem was with your not escaping the quote in I've; either that or you go with the double quotes option.

don graham
don graham
13,789 Points

The problem is in your document.write statement. You're using single quotes, which isn't entirely wrong, but you have to escape the apostrophe when using single-quotes. However, double quotes eliminate the need to escape the apostrophe. Consider surrounding your arguments with double-quotes, like this:

document.write ("I've been alive" + yearsAlive + "seconds");

If you use ES6 template literals you could do this:

document.write (`I've been alive ${yearsAlive} seconds`);
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi don! I've also changed your comment to an answer to allow for voting and best answer assignment. This will also have the added benefit of marking the question as answered in the forums. Thanks for your assistance in the Community! :sparkles:

Bee Priola
Bee Priola
3,922 Points

thank you don. it worked !!

Kabolobari Benakole
PLUS
Kabolobari Benakole
Courses Plus Student 14,278 Points

Ok, Bee. Glad to hear it worked. So, give Helmut the "best answer" mark then? Take care.