Blogger Information
Blog 38
fans 0
comment 3
visits 43865
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js基础学习-三角形和乘法表
意外的博客
Original
781 people have browsed it
<!DOCTYPE html>
<html>
<head>
	<title>三角形,九九乘法表作业</title>
	<meta charset="utf-8">
	<script type="text/javascript">


		// 直角三角形;for
	// for (var i=1; i<10 ; i++) { 
	// 	for (var k=1; k<i ; k++) { 
	// 		document.write ('*');
	// 	}
	// 		document.write ('*'+'<br>');
	// }


	// 九九乘法表;for
	// for (var i=1; i<10 ; i++) { 
	// 	for (var k=1; k<=i ; k++) { 
	// 		document.write (k+'x'+i+'='+i*k+'&nbsp');
	// 	}
	// 		document.write ('<br>');
	// }


	// 九九乘法表;while
	// var i=1;
	// while (i<10) {
	// 	var k=1;
	// 	while (k<=i) {
	// 		document.write( i+'*'+k+'='+ i*k +'&nbsp;&nbsp');
	// 		k++;
	// 	}
	// 	document.write( '<br>');
	// 	i++;	
	// }


	//等腰三角形;
	// var n=10;
	// for(var i=1;i<n;i++){
	// 	//要想n-i成立,下面就需要输出一个空格;
	// 	for(var k=1;k<=n-i;k++){
	// 		document.write('&nbsp');
	// 	}
	// 	for(var k=1;k<=i;k++){
	// 		//for循环输出需要加一个空格,不然显示的不会是等腰三角形
	// 		document.write('*'+'&nbsp');
	// 	}
	// 	document.write( '<br>');
	// }


// 思路:先输出左边的,用空格代替,然后输出右边的,
// 	相当于每行空白和*连接在一起;
	var n=10;
	var i=1;
	while(i<n){
		var k=1;
			// 因为下面用空格代替了一个*位子,所以这里n-i才可以成立;
			while(k<=n-i){
			document.write ('&nbsp');
			k++;
		}
		var k=1;
		while(k<=i){
			document.write ('*'+'&nbsp');
			k++;
		}
		document.write ('<br>');
		i++;
	}

	</script>
</head>
<body>

</body>
</html>

总结:做图形,一般从左向右排列的

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post