打印菱形图案(用*)
<script> for (let i = -3; i < 4; i++) { // 用到了y = |x|函数的思想 const empty = Math.abs(i % 4); let row = ''; for (let j = 0; j < empty; j++) { row += ' '; } for (let j = 0; j < 7 - empty * 2; j++) { row += '*'; } console.log(row); } </script>