打印空心三角形

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>空心三角形-JavaScript</title>
    </head>
    <body>
        <script type="text/javascript">
            var h = prompt("请输入三角形的高", 5);
            for(var q = 1; q < h; q++) {
                document.write(" ");
            }
            document.write("*" + "<br>");
            for(var i = 1; i < h - 1; i++) {
                for(var n = 1; n < h - i; n++) {
                    document.write(" ");
                }
                document.write("*");
                for(var j = 1; j <= 2 * i - 1; j++) {
                    document.write(" ");
                }
                document.write("*");
                document.write("<br>");
            }
            for(var m = 1; m <= 2 * h - 1; m++) {
                document.write("*");
            }
        </script>
    </body>
</html>

推荐阅读更多精彩内容