1. 程式人生 > >通過原生JS列印一個空心菱形圖案

通過原生JS列印一個空心菱形圖案

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文件</title>
</head>

<body>
</body>
</html>
<script>
    //    列印一個空心菱形圖案 
    for(var i = 1; i <=6 ; i++){
        for(var k = 1 ; k<=6-i; k++){
            document.write(
"-"); } for(var j = 1 ; j<=i*2-1; j++){ if(i == 1){ document.write("*"); }else if(j == 1 || j == i*2-1){ document.write("*"); }else{ document.write("-"); } } document.write(
"<br>"); } for(var i = 5; i >=1 ; i--){ for(var k = 1 ; k<=6-i; k++){ document.write("-"); } for(var j = 1 ; j<=i*2-1; j++){ if(i == 1){ document.write("*"); }else if(j == 1 || j == i*2-1){ document.write(
"*"); }else{ document.write("-"); } } document.write("<br>"); } </script>