Js arranged to make a star with a triangular

* Playing with a triangular arrangement, it should mainly decomposed. It is actually formed in a pattern with spaces * and combinations thereof. The number of spaces per line minus the current number of rows is the number of rows, the number of stars is 2x the current line number -1

 

// let the user enter the number of rows, using a nested for loop being played with the stars, the number of lines equal to the input digital
// For example: a user input 6
// *
// ***
// *****
// *******
// *********
// ***********
let readline = require("readline-sync");
console.log ( "Please enter the number of rows");
let line = readline.question("");
let strSpace = "";
let strStar = "";
let str = "";
for (let i = 1; i <= line; i++) {
for (let j = 1; j <= line - i; j++) {
strSpace = strSpace + " ";
}
for (let k = 1; k <= 2 * i - 1; k++) {
Strs Strs + = '*';
}
str = strSpace + strStar;
console.log(str);
str = "";
strSpace = "";
strStar = "";
}

Guess you like

Origin www.cnblogs.com/gao2/p/11408705.html