美文网首页
for循环实现*金字塔

for循环实现*金字塔

作者: 3cbb39ca03b7 | 来源:发表于2017-01-21 00:22 被阅读0次

    效果:

               *

             ***

           *****

          *******

    实现:

    <script>

    document.write("<p   align="center">");

    for(var  i=1;i<5;i++){

    for(var j=1;j<2*i-1;j++){

    document.write("*");

    }

    document.write("<br />");

    }

    document.write("</p>");

    </script>

    注:

    程序的经典之处:

    在一开始使用document.write("<p align="center">");p标签align属性的使用,可以直接出来所需效果,不用再去考虑每个*之前要输出多少个空格,去寻找空格的规律

    相关文章

      网友评论

          本文标题:for循环实现*金字塔

          本文链接:https://www.haomeiwen.com/subject/uhpgbttx.html