We help IT Professionals succeed at work.

# Html Newline

on
112 Views
Hi experts, I want to make 3 lines of the following sentence below. How? I wish to make 3 lines. Thanks!

var mm = "the quick brown fox jumped over the lazy dog"
Comment
Watch Question

## View Solutions Only

CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)

Commented:
Hi Leonidas, I've tried the code to achieve the result of 3 lines but it doesn't work.  I wish the result like this, which is in three lines

The
quick
brown

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)

Commented:
n is working on my project. Thank you Ryan Chong!

Commented:
Thanks a lot both of you Guys!
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
First i count the lenght of the string  and the divide this  with 3 to get the number of charachters of eaxh chunk.The follow the code that takes two arg.String anf the lenght that you found above

``````var mm = "the quick brown fox jumped over the lazy dog";
console.log(mm.length/3);

function chunkString(str, len) {
var size = Math.ceil(str.length/len),
retStr  = new Array(size),
offset
;

for (var i=0; i<size; i++) {
offset = i * len;
retStr[i] = str.substring(offset, offset + len);
}
console.log(retStr);

}
chunkString(mm, 16);
``````
At the end you can mofify the len arg so that you have all the words without slice

Commented:
Thank you so much Leonidas for giving me such brilliant techniques. More power and God bless!
Unlock the solution to this question.