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 trialHara Gopal K
Courses Plus Student 10,027 Pointshow can i print JavaScript Variables using html tags
how can i print the data in a JavaScript variable to the browser but using html tags and the document.write() method ?
1 Answer
Olga DC
16,680 PointsHi Hara. Here you have a couple of examples:
var aNumberVariable = 43;
var aStringVariable = 'Hello';
document.write('<p>You can write ' + aNumberVariable + ' or ' + aStringVariable + ' this way, inside a paragraph, for instance.<p>');
document.write(`<p>You can also do it this way: ${aNumberVariable} and ${aStringVariable}. Search for template literals.<p>`);
Hara Gopal K
Courses Plus Student 10,027 PointsHara Gopal K
Courses Plus Student 10,027 Pointsthank you olga :)