精华内容
下载资源
问答
  • js打印直角三角形杨辉三角

    千次阅读 2016-07-04 19:36:26
    js打印直角三角形杨辉三角 思路,用外面的数组去控制里面的数组,在边上的始终是1,而中间的元素始终是上一行相邻两个元素相加的和,根据规律不难得出一些结果,然后反复在火狐浏览器中测试,最后打出到控制台,...

    用js打印直角三角形杨辉三角


    思路,用外面的数组去控制里面的数组,在边上的始终是1,而中间的元素始终是上一行相邻两个元素相加的和,根据规律不难得出一些结果,然后反复在火狐浏览器中测试,最后打出到控制台,记得执行的时候按F12,


         

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>我的杨辉三角</title>
        <script>
            function test(){
                var arr = new Array();
                for(var i = 0 ;i < 20 ; i++){
                    if(i == 0){
                        arr.push(1);
                    }
                    else if(i == 1){
                        arr = new Array();
                        arr.push(1);
                        arr.push(1);
                    }
                    else{
                        var arr2 = new Array();
                        arr2.push(1);
                        for(var j = 0;j<arr.length - 1; j++){
                            arr2.push(arr[j] + arr[j+1]);
                        }
                        arr2.push(1);
                        arr = new Array();
                        arr = arr2;
                    }
                    console.log(arr.join(" "));
                }
            }test();
        </script>
    </head>
    <body>
    
    </body>
    </html>







    
    

    展开全文
  • 客户端软件技术的作业,要求根据输入的数值打印出各种形状。 首先是html部分 <h1>正三角形1</h1> <div> <input type="text" id="side1" placeholder="请输入您想要的正三角形的边长度" ...

    客户端软件技术的作业,要求根据输入的数值打印出各种形状。

    首先是html部分

    <h1>正三角形1</h1>
        <div>
            <input type="text" id="side1" placeholder="请输入您想要的正三角形的边长度" style="width: 300px;">
            <input type="button" onclick="one()" value="点我生成三角形">
            <div id="one" style="line-height: 10px;margin-top: 20px;"></div>
        </div>
        <h1>正三角形2</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side2" placeholder="请输入您想要的正三角形的边长度" style="width: 300px;">
            <input type="button" onclick="two()" value="点我生成正三角形">
            <div id="two"></div>
        </div>
        <h1>直角三角形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side3" placeholder="请输入行数" style="width: 300px;">
            <input type="button" onclick="three()" value="点我生成直角三角形">
            <div id="three"></div>
        </div>
        <h1>菱形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side4" placeholder="请输入菱形的边长" style="width: 300px;">
            <input type="button" onclick="four()" value="点我生成菱形">
            <div id="four" style="letter-spacing: 4px;"></div>
        </div>
        <h1>空心菱形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side5" placeholder="请输入菱形的边长" style="width: 300px;">
            <input type="button" onclick="five()" value="点我生成空心菱形">
            <div id="five" style="letter-spacing: 4px;"></div>
        </div>
        <h1>对角线菱形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side6" placeholder="请输入菱形的边长" style="width: 300px;">
            <input type="button" onclick="six()" value="点我生成对角线菱形">
            <div id="six" style="letter-spacing: 4px;"></div>
        </div>

    效果:

    正三角形:

    function one() { //点击按钮触发的函数
                var one = document.getElementById("one") //获取one,方便后续将三角形画在里面
                var html1 = '' //定义HTML1
                var side1 = document.getElementById("side1").value //获取输入的边的值
                if (!side1) { //判断side1是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side1)) { //在下方的函数中判断side1是否为正整数,否则给出提示
                    alert("请输入正整数哦")
                } else {
                    for (var i = 0; i < side1; i++) {
                        for (var j = 0; j <= i; j++) { //当j小于i时便输出
                            html1 += '*'
                        }
                        html1 += '<br/>'
                    }
                    one.innerHTML = html1 //将html在one中显示粗来
                }
    
            }
    

    效果:

    第二个正三角形:

     function two() { //点击正三角形按钮触发的函数
                var two = document.getElementById("two") //获取two,方便后续将等边三角形画在里面
                var html2 = '' //定义HTML2
                var side2 = document.getElementById("side2").value //获取输入的等边三角形的边的值
                if (!side2) { //判断side2是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side2)) { //判断side1是否为正整数,否则给出提示
                    alert("请输入正整数哦")
                } else {
                    for (var i = 0; i < side2; i++) {
                        for (var j = 0; j < side2 - i - 1; j++) {
                            html2 += '&nbsp'
                        }
                        for (var k = 0; k < i * 2 + 1; k++) {
                            if (k > i) { //每行只输入相应行数的*
                                html2 += '&nbsp'
                            } else {
                                html2 += '* '
                            }
                        }
                        html2 += '<br/>'
                    }
                    two.innerHTML = html2 //将html在two中显示粗来
                }
            }

    效果:

    直角三角形:

    function three() { //点击直角三角形触发的函数
                var three = document.getElementById("three") //获取three,方便后续将三角形画里边
                var html3 = ''
                var side3 = document.getElementById("side3").value //获取行数的值
                if (!side3) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side3)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数哦")
                } else {
                    for (i = 0; i < side3; i++) {
                        for (j = 0; j < 2 * i + 1; j++) {
                            html3 += '*'
                        }
                        html3 += '<br/>'
                    }
                    three.innerHTML = html3 //将html在three中显示粗来
                }
            }

    效果:

    菱形:

    function four() { //点击菱形按钮触发的函数
                var four = document.getElementById("four") //获取four,方便后续将图形画里边
                var html4 = ''
                var side4 = document.getElementById("side4").value //获取行数的值
                if (!side4) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side4)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数")
                } else {
                    for (var i = 0; i < side4; i++) { //输出正三角形               
                        for (var j = 0; j < side4 - i - 1; j++) {                                
                            html4 += '&nbsp'                    
                        }                   
                        for (var j = 0; j < 2 * i + 1; j++) {                                
                            if (j > i) { //每行只输入相应行数的*
                                html4 += '&nbsp'
                            } else {
                                html4 += '* '
                            }           
                        }                    
                        html4 += '<br/>';            
                    }         
                    for (var i = side4 - 2; i >= 0; i--) { //输出倒三角形,倒三角形最长的边应该比正三角形最长边小2              
                        for (var j = 0; j < side4 - i - 1; j++) {                                
                            html4 += '&nbsp'                    
                        }                                           
                        for (var j = 0; j < 2 * i + 1; j++) {                                        
                            if (j > i) { //每行只输入相应行数的*
                                html4 += '&nbsp'
                            } else {
                                html4 += '* '
                            }                           
                        }                            
                        html4 += '<br/>';                        
                    }                   
                    four.innerHTML = html4
                }
            }

    效果:

    空心菱形:

    function five() { //点击空心菱形触发的函数
                var five = document.getElementById("five") //获取five,方便后续将图形画里边
                var html5 = ''
                var side5 = document.getElementById("side5").value //获取行数的值
                if (!side5) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side5)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数")
                } else {        
                    for (var i = 0; i < side5; i++) { //输出正三角形                      
                        for (var j = 0; j < side5 - i - 1; j++) {                                                        
                            html5 += '&nbsp'                                            
                        }                                                      
                        for (var j = 0; j < 2 * i + 1; j++) {                                                        
                            if (j == 0 || j == 2 * i) { //只在最开始和最末尾打印*                                                                                  
                                html5 += '*'                                                           
                            } else {                                                                    
                                html5 += '&nbsp'                                                            
                            }                                                        
                        }                                                        
                        html5 += '<br/>';                                
                    }                                        
                    for (var i = side5 - 2; i >= 0; i--) {                                                  
                        for (var j = 0; j < side5 - i - 1; j++) {                                                                            
                            html5 += '&nbsp'                                                        
                        }                                                                  
                        for (var j = 0; j < 2 * i + 1; j++) { //同理,只在最开始和最末尾打印*                                                                    
                            if (j == 0 || j == 2 * i) {                                                                                      
                                html5 += '*'                                                                    
                            } else {                                                                                           
                                html5 += '&nbsp'                                                                        
                            }                                                        
                        }                                                        
                        html5 += '<br/>'                        
                    }    
                    five.innerHTML = html5                                            
                }
            }

    效果:

    对角菱形:

    function six() {
                var six = document.getElementById("six") //获取six,方便后续将图形画里边
                var html6 = ''
                var side6 = document.getElementById("side6").value //获取行数的值
                if (!side6) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side6)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数")
                } else {             
                    for (var i = 0; i < side6; i++) {                              
                        for (var j = 0; j < side6 - i - 1; j++) {                                                    
                            html6 += '&nbsp'                            
                        }                                        
                        for (var j = 0; j < 2 * i + 1; j++) {                                    
                            if (i == side6 - 1 && j < side6) {   //横线                                                  
                                html6 += '* '                                     
                            } else {
                                if (i == side6 - 1 && j >= side6) { //排除掉横线符合下面if的条件被意外写入的情况
                                    html6 += '&nbsp'
                                } else {
                                    if (j == 0 || j == 2 * i || j == i) { //在最前端、最末尾和最中间写上*                                                                    
                                        html6 += '*'                            
                                    } else {                                                                    
                                        html6 += '&nbsp'                                                                    
                                    } 
                                }                                                                                                       
                            }                                        
                        }                                            
                        html6 += '<br/>'                                   
                    }                                    
                    for (var i = side6 - 2; i >= 0; i--) {                                                                                                                
                        for (var j = 0; j < side6 - i - 1; j++) {                                                                                            
                            html6 += '&nbsp'                                                           
                        }                                                                      
                        for (var j = 0; j < 2 * i + 1; j++) {                                                                        
                            if (j == 0 || j == 2 * i || j == i) {                                             
                                html6 += '*'                                      
                            } else {                                                                                        
                                html6 += '&nbsp'                                           
                            }                                       
                        }                                                                                
                        html6 += '<br/>'                               
                    }                             
                    six.innerHTML = html6
                }
            }

    效果:

    说明:我这种方法画出来的十字不是很直,有其他方法的。

    最后是自己写的判断是否是正整数的函数:

    function isNum(num) { //判断传进来的数字是否是正整数
                var r = /^[0-9]*[1-9][0-9]*$/ //将正则写出来
                return r.test(num) //test()判断数字是否符合正则表达式
            }

    附上完整代码:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    
    <body>
        <h1>正三角形1</h1>
        <div>
            <input type="text" id="side1" placeholder="请输入您想要的正三角形的边长度" style="width: 300px;">
            <input type="button" onclick="one()" value="点我生成三角形">
            <div id="one" style="line-height: 10px;margin-top: 20px;"></div>
        </div>
        <h1>正三角形2</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side2" placeholder="请输入您想要的正三角形的边长度" style="width: 300px;">
            <input type="button" onclick="two()" value="点我生成正三角形">
            <div id="two"></div>
        </div>
        <h1>直角三角形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side3" placeholder="请输入行数" style="width: 300px;">
            <input type="button" onclick="three()" value="点我生成直角三角形">
            <div id="three"></div>
        </div>
        <h1>菱形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side4" placeholder="请输入菱形的边长" style="width: 300px;">
            <input type="button" onclick="four()" value="点我生成菱形">
            <div id="four" style="letter-spacing: 4px;"></div>
        </div>
        <h1>空心菱形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side5" placeholder="请输入菱形的边长" style="width: 300px;">
            <input type="button" onclick="five()" value="点我生成空心菱形">
            <div id="five" style="letter-spacing: 4px;"></div>
        </div>
        <h1>对角线菱形</h1>
        <div style="margin-top: 10px;">
            <input type="text" id="side6" placeholder="请输入菱形的边长" style="width: 300px;">
            <input type="button" onclick="six()" value="点我生成对角线菱形">
            <div id="six" style="letter-spacing: 4px;"></div>
        </div>
        <script>
            function one() { //点击按钮触发的函数
                var one = document.getElementById("one") //获取one,方便后续将三角形画在里面
                var html1 = '' //定义HTML1
                var side1 = document.getElementById("side1").value //获取输入的边的值
                if (!side1) { //判断side1是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side1)) { //在下方的函数中判断side1是否为正整数,否则给出提示
                    alert("请输入正整数哦")
                } else {
                    for (var i = 0; i < side1; i++) {
                        for (var j = 0; j <= i; j++) { //当j小于i时便输出
                            html1 += '*'
                        }
                        html1 += '<br/>'
                    }
                    one.innerHTML = html1 //将html在one中显示粗来
                }
    
            }
    
            function two() { //点击正三角形按钮触发的函数
                var two = document.getElementById("two") //获取two,方便后续将等边三角形画在里面
                var html2 = '' //定义HTML2
                var side2 = document.getElementById("side2").value //获取输入的等边三角形的边的值
                if (!side2) { //判断side2是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side2)) { //判断side1是否为正整数,否则给出提示
                    alert("请输入正整数哦")
                } else {
                    for (var i = 0; i < side2; i++) {
                        for (var j = 0; j < side2 - i - 1; j++) {
                            html2 += '&nbsp'
                        }
                        for (var k = 0; k < i * 2 + 1; k++) {
                            if (k > i) { //每行只输入相应行数的*
                                html2 += '&nbsp'
                            } else {
                                html2 += '* '
                            }
                        }
                        html2 += '<br/>'
                    }
                    two.innerHTML = html2 //将html在two中显示粗来
                }
            }
    
            function three() { //点击直角三角形触发的函数
                var three = document.getElementById("three") //获取three,方便后续将三角形画里边
                var html3 = ''
                var side3 = document.getElementById("side3").value //获取行数的值
                if (!side3) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side3)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数哦")
                } else {
                    for (i = 0; i < side3; i++) {
                        for (j = 0; j < 2 * i + 1; j++) {
                            html3 += '*'
                        }
                        html3 += '<br/>'
                    }
                    three.innerHTML = html3 //将html在three中显示粗来
                }
            }
    
            function four() { //点击菱形按钮触发的函数
                var four = document.getElementById("four") //获取four,方便后续将图形画里边
                var html4 = ''
                var side4 = document.getElementById("side4").value //获取行数的值
                if (!side4) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side4)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数")
                } else {
                    for (var i = 0; i < side4; i++) { //输出正三角形               
                        for (var j = 0; j < side4 - i - 1; j++) {                                
                            html4 += '&nbsp'                    
                        }                   
                        for (var j = 0; j < 2 * i + 1; j++) {                                
                            if (j > i) { //每行只输入相应行数的*
                                html4 += '&nbsp'
                            } else {
                                html4 += '* '
                            }           
                        }                    
                        html4 += '<br/>';            
                    }         
                    for (var i = side4 - 2; i >= 0; i--) { //输出倒三角形,倒三角形最长的边应该比正三角形最长边小2              
                        for (var j = 0; j < side4 - i - 1; j++) {                                
                            html4 += '&nbsp'                    
                        }                                           
                        for (var j = 0; j < 2 * i + 1; j++) {                                        
                            if (j > i) { //每行只输入相应行数的*
                                html4 += '&nbsp'
                            } else {
                                html4 += '* '
                            }                           
                        }                            
                        html4 += '<br/>';                        
                    }                   
                    four.innerHTML = html4
                }
            }
    
            function five() { //点击空心菱形触发的函数
                var five = document.getElementById("five") //获取five,方便后续将图形画里边
                var html5 = ''
                var side5 = document.getElementById("side5").value //获取行数的值
                if (!side5) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side5)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数")
                } else {        
                    for (var i = 0; i < side5; i++) { //输出正三角形                      
                        for (var j = 0; j < side5 - i - 1; j++) {                                                        
                            html5 += '&nbsp'                                            
                        }                                                      
                        for (var j = 0; j < 2 * i + 1; j++) {                                                        
                            if (j == 0 || j == 2 * i) { //只在最开始和最末尾打印*                                                                                  
                                html5 += '*'                                                           
                            } else {                                                                    
                                html5 += '&nbsp'                                                            
                            }                                                        
                        }                                                        
                        html5 += '<br/>';                                
                    }                                        
                    for (var i = side5 - 2; i >= 0; i--) {                                                  
                        for (var j = 0; j < side5 - i - 1; j++) {                                                                            
                            html5 += '&nbsp'                                                        
                        }                                                                  
                        for (var j = 0; j < 2 * i + 1; j++) { //同理,只在最开始和最末尾打印*                                                                    
                            if (j == 0 || j == 2 * i) {                                                                                      
                                html5 += '*'                                                                    
                            } else {                                                                                           
                                html5 += '&nbsp'                                                                        
                            }                                                        
                        }                                                        
                        html5 += '<br/>'                        
                    }    
                    five.innerHTML = html5                                            
                }
            }
    
            function six() {
                var six = document.getElementById("six") //获取six,方便后续将图形画里边
                var html6 = ''
                var side6 = document.getElementById("side6").value //获取行数的值
                if (!side6) { //判断输入框里的内容是否为空,否则给出提示
                    alert("请先输入哦")
                } else if (!isNum(side6)) { //判断文本框的内容是否是正整数,否则给出提示
                    alert("请输入正整数")
                } else {             
                    for (var i = 0; i < side6; i++) {                              
                        for (var j = 0; j < side6 - i - 1; j++) {                                                    
                            html6 += '&nbsp'                            
                        }                                        
                        for (var j = 0; j < 2 * i + 1; j++) {                                    
                            if (i == side6 - 1 && j < side6) {   //横线                                                  
                                html6 += '* '                                     
                            } else {
                                if (i == side6 - 1 && j >= side6) { //排除掉横线符合下面if的条件被意外写入的情况
                                    html6 += '&nbsp'
                                } else {
                                    if (j == 0 || j == 2 * i || j == i) { //在最前端、最末尾和最中间写上*                                                                    
                                        html6 += '*'                            
                                    } else {                                                                    
                                        html6 += '&nbsp'                                                                    
                                    } 
                                }                                                                                                       
                            }                                        
                        }                                            
                        html6 += '<br/>'                                   
                    }                                    
                    for (var i = side6 - 2; i >= 0; i--) {                                                                                                                
                        for (var j = 0; j < side6 - i - 1; j++) {                                                                                            
                            html6 += '&nbsp'                                                           
                        }                                                                      
                        for (var j = 0; j < 2 * i + 1; j++) {                                                                        
                            if (j == 0 || j == 2 * i || j == i) {                                             
                                html6 += '*'                                      
                            } else {                                                                                        
                                html6 += '&nbsp'                                           
                            }                                       
                        }                                                                                
                        html6 += '<br/>'                               
                    }                             
                    six.innerHTML = html6
                }
            }
    
            function isNum(num) { //判断传进来的数字是否是正整数
                var r = /^[0-9]*[1-9][0-9]*$/ //将正则写出来
                return r.test(num) //test()判断数字是否符合正则表达式
            }
        </script>
    </body>
    
    </html>

    今天是周末,依然是与学习死磕的一天,窗户外面一片生机,温度只有十度。但学习使我快乐~⚪祝前程似锦

    展开全文
  • 直角三角形 第一个循环i控制多少行 第二个循环j控制多少列 for (var i = 0; i < 5; i++) { //行 for (var j = 0; j <= i; j++) { //列 document.write('*') } document.write('<br>')//输出完一...

    正直角三角形

    第一个循环i控制多少行

    第二个循环j控制多少列

    		for (var i = 0; i < 5; i++) { //行
                 for (var j = 0; j <= i; j++) { //列
                     document.write('*')
                 }
                 document.write('<br>')//输出完一行了换行
            // }
    

    在这里插入图片描述

    倒直角三角形

    第一个循环i控制多少行

    第二个循环j控制多少列

    	for (var i = 0; i < 8; i++) {
                for (var j = 8 - i; j > 0; j--) {
                    document.write('*')
                }
                document.write('<br>')
            }
    

    在这里插入图片描述

    九九乘法表

    第一个循环i控制多少行

    第二个循环j控制多少列 根据行的大小来决定j的大小

    	for (var i = 1; i <= 9; i++) {
                for (var j = 1; j <= i; j++) {
                    document.write(j + '*' + i + '=' + i * j + "&nbsp&nbsp")
                }
                document.write('<br>')
            }
    

    在这里插入图片描述

    水仙花数

    解析看这一篇博客

    	var number1 = +prompt('请输入一个大于100的数:');
        var bai = parseInt(number1 / 100); //百位
        var shi = parseInt(number1 % 100 / 10) //十位
        var ge = number1 % 10 //个位
        console.log(bai, shi, ge)
        if ((bai ** 3 + shi ** 3 + ge ** 3) == number1) {
            console.log(number1 + "是水仙花数")
        } else {
            console.log(number1 + "不是水仙花数")
        }
    

    在这里插入图片描述

    展开全文
  • js实现"*"打印直角三角形、菱形、等腰三角形 效果图如下: 代码如下: 1.直角三角形 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>直角三角形</...

    js实现"*"打印直角三角形、菱形、等腰三角形

    效果图如下:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    代码如下:
    1.直角三角形

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>直角三角形</title>
    </head>
    <body>
    
    </body>
    <script>
        for(var i = 1;i<=5;i++){
            for(var j = 1;j<=i;j++){
                document.write("*");
            }
            document.write("<br>");
        }
    </script>
    </html>
    

    2.等腰三角形

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>三角形</title>
    </head>
    <body>
    
    </body>
    <script>
        var line = 5;
        for (var i = 1;i<=line;i++){
            for (var j = 1;j<=line-i;j++){
                document.write("&ensp;");
            }
            for (var k =1;k<=2*i-1;k++){
                document.write("*");
            }
    
            document.write("<br>");
        }
    
    </script>
    </html>
    

    3.菱形

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>菱形</title>
    </head>
    <body>
    
    </body>
    <script>
        var line = 9;
        for (var i=1;i<=line;i++){
            if (i<=5){
                for (var j = 1;j<=(line-(2*i-1))/2;j++){
                    document.write("&ensp;");
                }
                for (k =1;k<=2*i-1;k++){
                    document.write("*");
                }
                document.write("<br>");
            }
            if (i>5){
                for (m=1;m<=(line-((line-i)*2+1))/2;m++){//line-((line-i)*2+1))/2
                    document.write("&ensp;");
                }
                for (n = 1;n<=(line-i)*2+1;n++){
                    document.write("*");
                }
                document.write("<br>");
    
                }
        }
    </script>
    </html>
    
    展开全文
  • 打印五行五角星 //***** //***** //***** //***** //***** for(let i=0;i<5;i++){ for(let j=0;j<5;j++){ document.write("*")...打印直角三角形 //* //** //*** //**** //***** for(let i=1;i<=5;i++){.
  • 一.打印直角三角形 js代码: <script> for(var i=0;i<4;i++) { var s=""; for(var k=0;k<2*i+1;k++) { s+="*"; } console.log(s); } </script> 效果图: 二.打印
  • 1、js打印直角三角形 for(var i = 0; i < 5; i++){ for(var j = 0;j <= i; j++){ doucument.write('*'); } doucument.write('<br>'); } 结果如图所示: 2、打印倒直角三角形 for(var i = 0; i...
  • js页面打印三角形、等腰...1、直角三角形 for (let i = 0; i < 10; i++) { for (let j = 0; j < i; j++) { document.write('#') } document.write('</br>') } 2、等腰三角形 for (let i = 1...
  • JS打印三角形

    千次阅读 2019-08-31 20:16:07
    直角三角形 图一 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript"> for(let j=0;j...
  • 1、乘法口诀表 ...2、直角三角形 代码如下: 打印结果为: 3、等腰三角形 相比直角三角形,等腰三角形在前面多加了一些空格 代码如下 打印结果为: ...
  • 1.图一和图二是利用JS语句画出来的两个直角三角形,下边我以图一为例,说一下我的做法。 图一星号逐行递增, &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &...
  • js基础运用——js用*打印三角形,菱形

    万次阅读 多人点赞 2017-11-21 11:18:10
    js基础运用新手见解,有不足或更简单的方法希望各位指点1....图一图二是js语句利用*号画出来的直角三角形,方法思路都一致,下面以图一为例讲一下本人所用的方法:<!DOCTYPE html> <title>Document <scrip
  • 图一和图二是利用JS语句画出来的两个直角三角形,下边我以图一为例,说一下我的做法。 图一星号逐行递增,<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>...
  • JS三角形

    2019-09-24 01:21:50
    1、直角三角形 <script> for (var i = 1; i <= 10; i++) { //外层循环代表的是要循环的行数 for (var j = 0; j < i; j++) { //内层循环代表的是要打印的列数 document.write('* '); } document....

空空如也

空空如也

1 2
收藏数 37
精华内容 14
关键字:

js打印直角三角形