# New Lines in Javascript

**URL:** <https://forum.kirupa.com/t/new-lines-in-javascript/263166>\
**Category:** web dev\
**Created:** [June 13, 2008, 1:06am UTC](https://forum.kirupa.com/t/new-lines-in-javascript/263166 "2008-06-13T01:06:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GGMcGee](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@GGMcGee](https://forum.kirupa.com/u/GGMcGee)\
**Post date:** [June 13, 2008, 1:06am UTC](https://forum.kirupa.com/t/new-lines-in-javascript/263166/1 "2008-06-13T01:06:32Z")

</div>

Hi,

I’ve added in some “random quotes” Javascript code into a HTML page, and have been trying to create new lines for each line of a quote that is displayed on the page, but it doesn’t seem to be working.

As far as I know, from what I’ve read,  
is used to start a new line… or perhaps I’ve misinterpreted this and all it does is create a new line in the source code.

This is what I have, which isn’t working. The quote displays fine, except it doesn’t format it as _Blah Blah Blah_ as one line after the other,

> [@"Javascript"](#):
>
> \<script language=“JavaScript”\>  
> \<!–  
> var r\_text = new Array ();  
> r\_text[0] = “Blah Blah Blah  
> Blah Blah Blah  
> Blah Blah Blah  
> Blah Blah Blah”;  
> r\_text[1] = “1111111”;  
> r\_text[2] = “2222222”;  
> r\_text[3] = “3333333”;  
> r\_text[4] = “4444444”;  
> r\_text[5] = “5555555”;  
> r\_text[6] = “6666666”;  
> var i = Math.round(6\*Math.random());
> 
> document.write(r\_text\*);
> 
> //–\>  
> \</script\>

Can someone tell me what I should be doing?

I would like the first random quote to appear on the page formatted like this:  
Blah Blah Blah  
Blah Blah Blah  
Blah Blah Blah  
Blah Blah Blah

I hardly ever use Javascript, so I’m not that great at it. Any help is appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 13, 2008, 1:13am UTC](https://forum.kirupa.com/t/new-lines-in-javascript/263166/2 "2008-06-13T01:13:52Z")

</div>

what’s wrong with

r\_text[0] = “Blah Blah Blah\<br /\>Blah Blah Blah\<br /\>Blah Blah Blah\<br /\>Blah Blah Blah”;

?

---

<div class="post-metadata">

**Author:** ![bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bear](https://forum.kirupa.com/u/bear)\
**Post date:** [June 13, 2008, 2:13pm UTC](https://forum.kirupa.com/t/new-lines-in-javascript/263166/3 "2008-06-13T14:13:46Z")

</div>

[quote=sekasi;2341901]what’s wrong with

r\_text[0] = “Blah Blah Blah\<br /\>Blah Blah Blah\<br /\>Blah Blah Blah\<br /\>Blah Blah Blah”;

?[/quote]

I loathe you. Solving this before I got a crack.

As sekasi stated, using HTML here, instead of  
, is your best bet.  
is for spaces when it comes to HTML rendering. It will do a space break in the code, though. \<br /\> renders a break since it is outputting to HTML.

---

<div class="post-metadata">

**Author:** ![GGMcGee](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@GGMcGee](https://forum.kirupa.com/u/GGMcGee)\
**Post date:** [June 17, 2008, 1:22am UTC](https://forum.kirupa.com/t/new-lines-in-javascript/263166/4 "2008-06-17T01:22:29Z")

</div>

Thanks. I just didn’t know normal HTML \<br /\> tags could be used. Silly of me. XD
