我今天刚开始使用 javascript 来完成一项学校任务。我的任务是用星星制作菱形图案,但我不明白如何制作底部金字塔
我试过改变一切,这段代码在我脑海中起作用但没有正确执行。这是我制作的代码
function clicked() {
var x = document.getElementById("num").value;
if (x < 50) {
document.write("Your Number is: " + x + "<br />Your number is lower than 50<br />");
} else if (x > 50) {
document.write("Your Number is: " + x + "<br />Your number is more than50<br />");
} else {
document.write("Your Number is: " + x + "<br />Your number is equal to 50<br />");
}
for (var i = 1; i <= x; i++) {
for (var k = 1; k <= x - i; k++) {
document.write(" ");
}
for (var j = 1; j <= i; j++) {
document.write("*");
}
document.write("<br/>");
}
var m = 1;
for (var l = x - m; l <= x - m; m++) {
for (var n = 1; n <= l; n++) {
document.write("*");
}
document.write("<br/>");
}
}
<body>
<input type="number" id="num" placeholder="Enter Number">
<br>
<button onclick="clicked()">SUBMIT</button>
</body>
神不在的星期二
相关分类