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 trialBee Priola
3,922 PointsWhat 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');
3 Answers
Helmut Granda
10,343 PointsYou 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
Treehouse TeacherHi! 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!
Kabolobari Benakole
Courses Plus Student 14,278 PointsI 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
13,789 PointsThe 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
Treehouse TeacherHi 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!
Bee Priola
3,922 Pointsthank you don. it worked !!
Kabolobari Benakole
Courses Plus Student 14,278 PointsOk, Bee. Glad to hear it worked. So, give Helmut the "best answer" mark then? Take care.
Shivang Chaturvedi
2,600 PointsShivang Chaturvedi
2,600 PointsTry 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);