Web Programming: JavaScript: how to manage a multi-line string
The tutor tells a trick for printing long strings with JavaScript.
Suppose you have a long string, over many lines, that you want to print with JavaScript.
Typically, to print a string, you might assign it to a variable, then print the variable:
var string_0=”Getting ready for Christmas…(and so on)…”;
document.getElementById(“div_0”).innerHTML=string_0;
document.getElementById(“div_0”).innerHTML=string_0;
In my experience, if the program you’re using puts a line break in the string, that seems okay. However, JavaScript may not allow an explicit line break in a string variable:
var string_0=”Getting
ready
for
Christmas”; seems not to work
ready
for
Christmas”; seems not to work
Nonetheless,
var string_0=”Getting “+
“ready “+
“for “+
“Christmas….”;
“ready “+
“for “+
“Christmas….”;
will print as
That’s what I’ve noticed, anyhow:)
Source:
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.
Leave a Reply
You must be logged in to post a comment.