Home > front end >  Solve??
Solve??

Time:10-11

How to use js to write such a graph, you need to set up with odd number of rows, solving

CodePudding user response:

 var line=4; 
Var arr=[];
for(var i=0; iIf (I==0)
{
Arr. Push (repeat (' * ', line * 2-1));
} else {
Arr. Push (repeat repeat (' ', I) + (' * '(line - I) * 2-1) + repeat ('', I))
Arr. Unshift (repeat repeat (' ', I) + (' * '(line - I) * 2-1) + repeat ('', I))
}
//arr. Push []
}
The console. The log (arr. Join (' \ n '))
The function repeat (STR, times) {
Return the new Array (+ 1) times. Join (STR);
}

CodePudding user response:

Why the console output is vertical, to the document. The write becomes a row

CodePudding user response:

Document. Write the input to the page, this is HTML
If the document must be used. The write, then add the pre or XMP at before and after the tag

 
*
* * *
* * * * *
* * *
*


So you can according to the text format shows