我最近有一项任务是根据用户给出的随机高度做一个空三角形。
它必须看起来像那样,但用户是可以设置高度的人。
我的脚本现在看起来像这样:
var hgh = prompt("Set the triangle's height: ");
document.write("<center><pre>");
for (var i = 1; i <= hgh ; i++) {
var s = "";
for (var j = 1; j <= (2 * hgh - 1); j++) {
if (i != hgh ) {
if (j == hgh + 1 - i || j == hgh - 1 + i) {
s += "X";
}
else {
s += " ";
}
}
else {
s += "X";
}
}
document.write(s);
document.write("<br>");
}
document.write("</pre></center>");
我必须更正脚本的哪一部分才能正确显示三角形?