SOURCE

console 命令行工具 X clear

                    
>
console
      for (let i = 1; i <= 4; i++) {
          var str = " ";
        for (let j = 3; j >= i; j--) {
          str +="\xa0\xa0";
        }
        for (let j = 1; j <= 2 * i - 1; j++) {
          str+='*';
        }
        console.log(str);
      }
      for (let i = 3; i >= 1; i--) {
        var str = " ";
        for (let j = 1; j <= 4 - i; j++) {
          str +="\xa0\xa0";
        }
        for (let j = 1; j <= 2 * i - 1; j++) {
          str+='*';
        }
        console.log(str);
      }
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>菱形</title>
	<script type="text/javascript"></script>
</head>
<body>
	<h2>菱形</h2>
</body>
</html>