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

How do I print outputs on different lines instead of them printing on the same lines?

var firstName = "Steve";

document.write(firstName.toUpperCase());

document.write(firstName.toLowerCase());

this outputs; STEVEsteve

I want it to look like this; STEVE steve

2 Answers

Mark Pryce
Mark Pryce
8,804 Points

You can just simply ad a <br> tag to your string. like so,

var firstName = "Steve <br>";

document.write(firstName.toUpperCase());

document.write(firstName.toLowerCase());

If you insert valid html into the document itself via a string then the browser should treat it as such.

Happy Coding!

Here is a way to add spaces or new lines:

var firstName = "Steve";
var space = " ";
var newLine = "<br>";

document.write(firstName.toUpperCase() );
document.write(newLine);
document.write(firstName.toLowerCase());
document.write(newLine);
document.write(firstName.toUpperCase() );
document.write(space);
document.write(firstName.toLowerCase());