均打印在浏览器的控制台
直角在右下的三角形
<script>
//右下角三角形
var alt = "";
for(var i=1; i<=7; i++){
var blank = "";
for(var j=1; j<=7-i; j++){ //打印空格
blank += " ";
}
var stars = "";
for(var m=1; m<=i; m++){ //打印*
stars += "*";
}
alt += blank + stars + "\n"; //字符串的拼接,拼为一行
}
console.log(alt);
</script>
等腰三角形
<script>
//等腰三角形
var alt = "";
for(var i=1; i<=5; i++){
var blank = "";
for(var j=1; j<=5-i; j++){ //打印空格
blank += " ";
}
var stars = "";
for(var m=1; m<=2*i-1; m++){ //打印*
stars += "*";
}
alt += blank + stars + "\n"; //字符串的拼接,拼为一行
}
console.log(alt);
</script>
菱形
<script>
//菱形
var alt = "";
var _num = 5;
for(var i=1; i<=_num; i++){
var blank = "";
for(var j=1; j<=_num-i; j++){ //打印空格
blank += " ";
}
var stars = "";
for(var m=1; m<=2*i-1; m++){ //打印*
stars += "*";
}
alt += blank + stars + "\n"; //字符串的拼接,拼为一行
}
for(var i=_num-1; i>0; i--){ //打印的行数要减1
var blank = "";
for(var j=1; j<=_num-i; j++){ //打印空格
blank += " ";
}
var stars = "";
for(var m=1; m<=2*i-1; m++){ //打印*
stars += "*";
}
alt += blank + stars + "\n"; //字符串的拼接,拼为一行
}
console.log(alt);
</script>