<!DOCTYPE html>
< html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript">
var cols=prompt('请输入金字塔行数:');
cols = Number(cols);
for (var i = 1; i <= cols; i++) {
for(var j = 0; j<cols+i-1; j++){ //判断打印空格和*的个数
if(i+j<=cols-1){
document.write(' ');
}else{
document.write('*');
}
}
document.write('<br/>');
}
</script>
</head>
<body>
</body>
< /html>
< html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript">
var cols=prompt('请输入金字塔行数:');
cols = Number(cols);
for (var i = 1; i <= cols; i++) {
for(var j = 0; j<cols+i-1; j++){ //判断打印空格和*的个数
if(i+j<=cols-1){
document.write(' ');
}else{
document.write('*');
}
}
document.write('<br/>');
}
</script>
</head>
<body>
</body>
< /html>