Welcome to the Treehouse Community
Looking to learn something new?
Erik RoblesCourses 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.
Steven Parker221,106 Points
When posting code, always use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. 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>");