JavaScript书写等腰三角形,菱形,九九乘法表,

一.等腰三角形

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script type="text/javascript">
		function show(row){
			for (var i = 1; i < row; i++) {
				for(var j=1;j<row-i;j++){
					  document.write('&ensp;');
				}
				for(var k=1;k<=2*i-1;k++){
					document.write('*');
				}document.write('<br>');
			}
		}
		show(7);
	</script>
</body>
</html>

二.菱形

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script type="text/javascript">
	function show(row){
			for (var i = 1; i < row; i++) {
				for(var j=1;j<row-i;j++){
					  document.write('&ensp;');
				}
				for(var k=1;k<=2*i-1;k++){
					document.write('*');
				}document.write('<br>');
			}
			    for(var s=2;s<row;s++){
			    	for(var a=1;a<s;a++){
			    		document.write('&ensp;');
			    	}
			    	for(var b=1;b<=(row-a)*2-1;b++){
			    		document.write('*');
			    	}document.write('<br>');
			    }
		}
		show(7);
	</script>
</body>
</html>

三.九九乘法表

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script type="text/javascript">
	function show(num){
             for(var i=1;i<num;i++){
              for(var a=1;a<=i;a++){
                 var b=a*i;
                 if (b<10) {
                    b='&ensp;'+b
                 }
                 document.write(a+'x'+i+'='+b+"&nbsp;&nbsp;&nbsp;")
              }document.write('<br>');
         } 
        }show(10);
	</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44382073/article/details/86222471