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) Working With Numbers Doing Math

Alfredo Galli
Alfredo Galli
4,290 Points

how do you get JavaScript to display the result on a separate line?

I've done the math and all seems to work with the right spacing, but I would love to know how to go down a line, I've tried normal HTML but then it turns out blank xD

The joys of being a newbie

var secondsPerMin = 60;
var minsPerHour = 60;
var hoursPerDay = 24;
var daysPerWeek= 7;
var weeksPerYear = 52;
var secondsPerDay= secondsPerMin * minsPerHour * hoursPerDay;
document.write('There are '+ secondsPerDay + ' seconds in a day ');
var secondsAlive = 34 * (secondsPerDay * daysPerWeek * weeksPerYear);
document.write("I've been alive for more then " + secondsAlive + ' seconds');

4 Answers

Patrik Horváth
Patrik Horváth
11,110 Points

so as i see you use document. .... so you using JS on website so you need HTML into it :)

add to your JS write BR tag represent Break :)

<br>

or use P tag why ? P tag is Block LEVEL element :) you learn more by passing HTML or CSS class :)

document.write("<p> TEXT </p>");
document.write("<p> TEXT 2 </p>");
Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You could also use \n which will create a new line.

example

document.write("\nI've been alive for more then " + secondsAlive + ' seconds'); // noticed the \n at the beginning

This doesn't work for me.

Jaime Serradell
Jaime Serradell
3,350 Points

With <br> tag. Like this :

document.write('There are '+ secondsPerDay + ' seconds in a day<br>');

Always inside of the string. Remember when you use an <h1>, <h2>.. or <p> tags, carriage return is included, it's not necessary put a <br> tag at the end. Hope i've help.

document.write("I've been alive for more than " + secondsAlive + " seconds "