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) Storing and Tracking Information with Variables Working with Strings and Finding Help

Chintan Ray
seal-mask
.a{fill-rule:evenodd;}techdegree
Chintan Ray
Full Stack JavaScript Techdegree Student 12,309 Points

how do we use an <h2> tag to write a var directly into the HTML file?

Hi everyone,

I was trying to put the shoutOut variable directly into the Index.html file using the document.write() method. if we put just the variable shoutOut into the code like document.write(shoutOut), the size of the text is really small. I wanted to use the <h2> tag to increase the font size, does anyone know how to do that? below is my code, but it prints out the word " shoutOut " instead of the value in the variable shoutOut. Any help would be useful.

var shout = prompt("Write something");

var shoutOut = shout.toUpperCase();

shoutOut += "!!!!";

document.write("<h2>shoutOut</h2>");

Thank you again, appreciate your help.

Cheers.

1 Answer

Steven Parker
Steven Parker
231,269 Points

There are a number of ways to do this, but the simplest is probably concatenation (joining strings together) with the "+" operator:

document.write("<h2>" + shoutOut + "</h2>");

But be aware that while this will display on the page in the browser, it does not add anything to the index.html file.