JS console print the stars, there is always that a na ~ ~ you want to be careful you heart oh ~~~ ❤

Print the stars in the console with JS statement, you is which one do you want to come to claim it ~ ~

1. Left at right angles to the stars

effect:

Code:

Copy the code
The require readline = let ( "readline-Sync"); 
console.log ( "Please enter the number of stars you want the line:"); 
let Row = parseInt (readline.question ( "")); 
// left-right-angled triangle 
let = STAR1 ""; 
the console.log ( "you want" + row + "left-right-angled star line is as follows:"); 
for (the let I = 0; I <row; I ++) { 
    STAR1 + = "*"; 
    the console.log (STAR1); 
}
Copy the code

 

2. Right at right angles to the stars

effect:

Code:

Copy the code
// right-right-angled triangle 
the let STAR2 = ""; 
the console.log ( "you want" + row + "Right at right angles to the line of stars follows:"); 
for (the let I = 0; I <Row; I ++) { 
    the let Space = ""; // spaces before stars each line; 
    for (the let J = 0; J <row-. 1-I; J ++) { 
        space + = ""; 
    } 
    STAR2 + = "*"; 
    the console.log (space + STAR2) ; 
}
Copy the code

 

3. pyramid stars

effect:

Code:

Copy the code
//金字塔星星
console.log("你想要的"+row+"行的金字塔星星如下:");
for(let i=0;i<row;i++){
    let star3="";
    for(let j=0;j<2*i+1;j++){
        star3+="*";
    }
    let space="";
    for(let j=0;j<row-1-i;j++){
        space+=" ";
    }
    console.log(space+star3);
}
Copy the code

 

4.倒左直角星星

效果:

代码:

Copy the code
//倒左直角星星
console.log("你想要的"+row+"行的倒左直角星星如下:");
for(let i=0;i<row;i++){
    let star4="";
    for(let j=0;j<row-i;j++){
        star4+="*";
    }
    console.log(star4);
}
Copy the code

 

5.倒右直角星星

效果:

代码:

Copy the code
//倒右直角星星
console.log("你想要的"+row+"行的倒右直角星星如下:");
for(let i=0;i<row;i++){
    let star5="";
    for(let j=0;j<row-i;j++){
        star5+="*";
    }
    let space="";
    for(let j=0;j<i;j++){
        space+=" ";
    }
    console.log(space+star5);
}
Copy the code

 

6.倒金字塔星星

效果:

代码:

Copy the code
//倒金字塔星星
console.log("你想要的"+row+"行的倒金字塔星星如下:");
for(let i=0;i<row;i++){
    let star6="";
    for(let j=0;j<2*(row-i)-1;j++){
        star6+="*";
    }
    let space="";
    for(let j=0;j<i;j++){
        space+=" ";
    }
    console.log(space+star6);
}
Copy the code

 

7.右箭头星星

效果:

代码:

Copy the code
//右箭头星星,上下拼接左直角星星和倒左直角星星
console.log("你想要的"+row+"行的右金字塔星星如下:");
let star7="";
for(let i=0;i<row/2;i++){
    star7+="*";
    console.log(star7);
}
for(let i=0;i<parseInt(row/2);i++){
    let star7="";
    for(let j=0;j<parseInt(row/2)-i;j++){
        star7+="*";
    }
    console.log(star7);
}
Copy the code

 

8.左箭头星星

效果:

代码:

Copy the code
//左箭头星星,上下凭借右直角星星和倒右直角星星
console.log("你想要的"+row+"行的左箭头星星如下:");
let star8="";
for(let i=0;i<row/2;i++){
    star8+="*";
    let space="";
    for(let j=0;j<parseInt(row/2)-i;j++){
        space+=" ";
    }
    console.log(space+star8);
}
for(let i=0;i<parseInt(row/2);i++){
    let space="";
    for(let j=0;j<=i;j++){
        space+=" ";
    }
    let star8="";
    for(let j=0;j<parseInt(row/2)-i;j++){
        star8+="*"
    }
    console.log(space+star8);
}
Copy the code
 
 

用JS语句,在控制台中打印星星,你要的是哪一款呢~来认领吧~

1.左直角星星

效果:

代码:

Copy the code
let readline=require("readline-sync");
console.log("请输入你想要的星星行数:");
let row=parseInt(readline.question(""));
//左直角三角形
let star1="";
console.log("你要的"+row+"行的左直角星星如下:");
for(let i=0;i<row;i++){
    star1+="*";
    console.log(star1);
}
Copy the code

 

2.右直角星星

效果:

代码:

Copy the code
//右直角三角形
let star2="";
console.log("你要的"+row+"行的右直角星星如下:");
for(let i=0;i<row;i++){
    let space="";//每行星星前的空格;
    for(let j=0;j<row-1-i;j++){
        space+=" ";
    }
    star2+="*";
    console.log(space+star2);
}
Copy the code

 

3.金字塔星星

效果:

代码:

Copy the code
//金字塔星星
console.log("你想要的"+row+"行的金字塔星星如下:");
for(let i=0;i<row;i++){
    let star3="";
    for(let j=0;j<2*i+1;j++){
        star3+="*";
    }
    let space="";
    for(let j=0;j<row-1-i;j++){
        space+=" ";
    }
    console.log(space+star3);
}
Copy the code

 

4.倒左直角星星

效果:

代码:

Copy the code
//倒左直角星星
console.log("你想要的"+row+"行的倒左直角星星如下:");
for(let i=0;i<row;i++){
    let star4="";
    for(let j=0;j<row-i;j++){
        star4+="*";
    }
    console.log(star4);
}
Copy the code

 

5.倒右直角星星

效果:

代码:

Copy the code
//倒右直角星星
console.log("你想要的"+row+"行的倒右直角星星如下:");
for(let i=0;i<row;i++){
    let star5="";
    for(let j=0;j<row-i;j++){
        star5+="*";
    }
    let space="";
    for(let j=0;j<i;j++){
        space+=" ";
    }
    console.log(space+star5);
}
Copy the code

 

6.倒金字塔星星

效果:

代码:

Copy the code
//倒金字塔星星
console.log("你想要的"+row+"行的倒金字塔星星如下:");
for(let i=0;i<row;i++){
    let star6="";
    for(let j=0;j<2*(row-i)-1;j++){
        star6+="*";
    }
    let space="";
    for(let j=0;j<i;j++){
        space+=" ";
    }
    console.log(space+star6);
}
Copy the code

 

7.右箭头星星

效果:

代码:

Copy the code
//右箭头星星,上下拼接左直角星星和倒左直角星星
console.log("你想要的"+row+"行的右金字塔星星如下:");
let star7="";
for(let i=0;i<row/2;i++){
    star7+="*";
    console.log(star7);
}
for(let i=0;i<parseInt(row/2);i++){
    let star7="";
    for(let j=0;j<parseInt(row/2)-i;j++){
        star7+="*";
    }
    console.log(star7);
}
Copy the code

 

8.左箭头星星

效果:

代码:

Copy the code
// Left arrow stars, at right angles to the right and down with the stars and down at right angles to the right stars 
console.log ( "what you want" + row + "Left arrow Star line is as follows:"); 
the let = star8 ""; 
for (i = the let 0; I <Row / 2; I ++) { 
    star8 + = "*"; 
    the let Space = ""; 
    for (the let J = 0; J <the parseInt (Row / 2) -i; J ++) { 
        Space + = ""; 
    } 
    the console.log (Space + star8); 
} 
for (the let I = 0; I <the parseInt (Row / 2); I ++) { 
    the let Space = ""; 
    for (the let J = 0; J <= I; J ++) { 
        + = Space ""; 
    } 
    the let = star8 ""; 
    for (the let J = 0; J <the parseInt (Row / 2) -i; J ++) { 
        star8 + = "*" 
    } 
    the console.log (Space + star8); 
}
Copy the code

Guess you like

Origin www.cnblogs.com/sugartang/p/11373933.html