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

Erik Robles
Erik Robles
Courses Plus Student 10,635 Points

P tag plus concatenation of string and variable

I am trying to use P tags in my code which is a concatenatin of strings and variables using the document.write function. I only get what I literally write on the screen as a result.

var secondsPerMin = 60; var minsPerHour = 60; var secondsPerMin = 60; var hoursPerDay = 24; var daysPerWeek = 7; var weeksPerYear = 52; var daysPerYear = 365; var yourName = prompt("What is your name?"); var secondsPerDay = secondsPerMin * minsPerHour * hoursPerDay; var yourAge = prompt("Enter your age"); var ageInSeconds = yourAge * secondsPerDay * daysPerYear; document.write("<p>yourName + ', '</P>"); document.write("<p>'You have been alive for ' + ageInSeconds + ' seconds'</p>);

This does not work nor does puttin a \ in my closing tags. Please help. Thank you.

2 Answers

Steven Parker
Steven Parker
230,024 Points

When posting code, always use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down: ย  Or watch this video on code formatting.

Now without formatting, I'm not sure if I'm seeing the real code; but it appears that you have some mismatched and/or misplaced quote marks in your last statements. If I have correctly interpreted your intentions, those lines of code should probably look more like this:

document.write("<p>" + yourName + ",</p>");
document.write("<p>You have been alive for " + ageInSeconds + " seconds</p>");