js打印正三角
<div id="triangle"></div>
<style>
#triangle{font-size: 30px;}
</style>
<script>
let str='';
let ele = document.getElementById('triangle');
function triangle(num=3){
for (let i = 0; i <= num; i++) {
str = i+1;
ele.innerHTML += "* ".repeat(str)+"<br/>";
}
}
triangle(9)
评论区