Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
221,106 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>");