刚学JAVASCRIPT有个东西不懂大家帮帮啊

来源:百度知道 编辑:UC知道 时间:2024/05/18 02:03:24
******hello world!
*****hello world!
****hello world!
***hello world!
**hello world!
*hello world!
上面的字符怎么搞出来啊.就是前面有多个*号没循环一次*号减1个

你弄两个for循环啊
for(var i=6;i>=1;i--)
{
for(var j=1;j<=i;j++)
{
document.write("*");
}
document.write("hello world!<br/>");
}

var star = '******';
var hello = 'hello world!';
for (var i=6;i>0;i--){
document.write( star.substring(0,i)+hello+"<br />" );
}

//下面的是全部代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function aa(){
for(var i = 6;i>0;i--){
for(var j = 0;j<i;j++){
document.write("*");
}
document.write("hello world!<br>");
}
}
</script>
</head>

<body onload="aa()">
</body>
</html>