//第一个
for (var i = 1; i <= 4; i++) {
for (var j = 1; j <= 4; j++) {
str1 += "*";
}
str1 += srr;
}
document.write(str1);
document.write(srr);
//第二个
var str2 = "";
for (var i = 1; i <= 4; i++) {
for (var j = 1; j <= i; j++) {
str2 += "*";
}
str2 += srr;
}
document.write(str2);
document.write(srr);
//第三个
var str3 = "";
// str3+='*';
for (var i = 1; i <= 4; i++) {
for (var j = 1; j <= 2 * i - 1; j++) {
str3 += "*";
}
str3 += srr;
}
document.write(str3);
document.write(srr);
//第四个
for (var i = 1; i <= 4; i++) {
var str4 = ""; // *
var srr2 = " "; //空格
for (var j = 1; j <= 4 - i; j++) {
srr2 += " ";
}
for (var k = 1; k <= 2 * i - 1; k++) {
str4 += "*";
}
str4 += srr;
document.write(srr2 + str4);
}
document.write(srr);
document.write(srr);
<script>
// D图星星
var str = "";
var srr = " ";
var sbb = "</br>";
document.write("<h3>D</h3>");
for (var i = 1; i <= 4; i++) {
//行数
for (var k = i; k <= 3; k++) {
//空格数
str += " ";
}
for (var j = 1; j <= 2 * i - 1; j++) {
str += "*";
}
str += sbb;
}
document.write(srr + str);
var str1 = "";
document.write("<h3>E</h3>");
for (var i = 1; i <= 4; i++) {
//行数
for (var k = i; k <= 3; k++) {
//空格数
str1 += " ";
}
for (var j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1) {
//每一行的第一列和最后一列才输出*
str1 += "*";
} else {
str1 += " "; //其余的输出空格
}
}
str1 += sbb;
}
document.write(str1);
var str2 = "";
document.write("<h3>G</h3>");
for (var i = 1; i <= 4; i++) {
//行数
for (var k = i; k <= 3; k++) {
//空格数
str2 += " ";
}
for (var j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1) {
//每一行的第一列和最后一列才输出*
str2 += "*";
} else {
str2 += " "; //其余的输出空格
}
}
str2 += sbb;
}
for (var i = 3; i >= 1; i--) {
//行数
for (var k = i; k <= 3; k++) {
//空格数
str2 += " ";
}
for (var j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1) {
//每一行的第一列和最后一列才输出*
str2 += "*";
} else {
str2 += " "; //其余的输出空格
}
}
str2 += sbb;
}
document.write(str2);
var str3 = "";
var row = 4;
document.write("<h3>F</h3>");
for (var i = 1; i <= row; i++) {
//行数
for (var k = i; k <= row - 1; k++) {
//空格数
str3 += " ";
}
for (var j = 1; j <= 2 * i - 1; j++) {
if (j == 1 || j == 2 * i - 1 || i == row) {
//每一行的第一列和最后一列才输出*
str3 += "*";
} else {
str3 += " "; //其余的输出空格
}
}
str3 += sbb;
}
document.write(str3);
</sciript>