var i;
for(i=10; i>=0; i= i-1){
var s;
for(s=0; s<i; s = s+1){
document.write("*");
}
//i want this to print a new line
/document.write(?);
}
I am printing a pyramid of stars, I can't get the new line to print.
var i;
for(i=10; i>=0; i= i-1){
var s;
for(s=0; s<i; s = s+1){
document.write("*");
}
//i want this to print a new line
/document.write(?);
}
I am printing a pyramid of stars, I can't get the new line to print.
For adding a new line use
For adding space use
or
how about:
(assuming you are in an html page, since a line feed alone will only show as a space)
In html page:
but if you are in JavaScript file, then this will work as new line:
To create a new line, symbol is '\n'
If you are outputting to the page, you'll want to use
"<br/>"
instead of'/n'
;Escape characters in JavaScript
document.writeln()
is what you are looking for ordocument.write('\n' + 'words')
if you are looking for more granularity in when the new line is used\n --> newline character is not working for inserting a new line.
But if we use below code then it works fine and it gives new line.