JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge

Hara Gopal K
Hara Gopal K
Pro Student 10,027 Points

how 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
Olga DC
16,680 Points

Hi 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>`);