Blogger Information
Blog 12
fans 0
comment 0
visits 7530
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript第2课:语句结构与函数_九九乘法表_2019.3.26
风雨中的脚步的博客
Original
584 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<div style='text-align:center;'>
	<script>
		for (var j = 1; j <= 9; j++) {       //j是显示行的数量
			for (var i = 1; i <= j; i++) {   //i是显示列的数量,随着i的递增列数会逐行递减
				var n='   '  //间隔的空格
				if (j*i<10) {              //结果为个位数的多连接2个空格
					n+='  '
				};
				document.write(i+'x'+j+'='+(i*j)+n);  //组装样式
			}
			document.write('<br>');   //每输出一遍换一行
		}

		var i=1;
		while(i<=9){
			var j=1;
			while(j<=i){
				var n='   '
				if((j==2&&i==4)||(j==2&&i==3)){   //调整个别不整齐的位置
					n+='  '
				}
				document.write(j+'x'+i+'='+(i*j)+n);
				j++;
			}
			document.write('<br>');
			i++;
		}
		var i=9;
		while(i<=9&&i>0){
			var j=1;
			while(j<=i){
				var n='   '
				if((j==2&&i==4)||(j==2&&i==3)){
					n+='  '
				}
				document.write(j+'x'+i+'='+(i*j)+n);
				j++;
			}
			document.write('<br>');
			i--;
		}

		var y=1;
		while(y<=60){
			var x=1;
			while(x<=y){
				document.write('*');
				x++;
			}
			document.write('<br>');
			y+=6;
		}
		var y=25;
		while(y<=60){
			var x=1;
			while(x<=y){
				document.write('*');
				x++;
			}
			document.write('<br>'); 
			y+=6;
		}
		var y=1;
		while(y<=10){
			var x=1;
			while(x<=17){
				document.write('*');
				x++;
			}
			document.write('<br>');
			y++;
		}

		var i=1;     //简便方法
		var a='¥';
		var b='¥';
		while(i<=5){
			document.write(a+'<br>');
			a=a+b;
			i++;
		}
	</script>
</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

if语句适合用在分支结构较少的语句中

switch则适合在较多的分支语句结构中使用

for循环通常用在有固定循环次数的循环语句中

while语句则用在满足某种条件时才循环的语句中,它们都是先判断条件是否满足再执行语句

do-while语句它先执行循环语句,再判断条件是否满足,也就是说,循环语句至少能执行一次

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