当前位置:网站首页>JS output shape

JS output shape

2022-06-27 07:35:00 I am the sun?

js Output 5*5 Star rectangle for

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>Document</title>
	<script type="text/javascript">
		for(var i = 1;i <= 5;i++){
			for(var j = 1;j <= 5;j++){
				document.write("*");
			}
			document.write("<br />");
		}
	</script>
</head>
<body>
	
</body>
</html>

Running results :
 Insert picture description here

js Output right triangle

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>Document</title>
	<script type="text/javascript">
//		for(var i = 1;i <= 5;i++){
//			for(var j = 1;j <= 5;j++){
//				document.write("*");
//			}
//			document.write("<br />");
//		}
		
		for(var i = 1;i <= 5;i++){
			for(var j = 1;j <= i;j++){
				document.write("*");
			}
			document.write("<br />");
		}
	</script>
</head>
<body>
	
</body>
</html>

Running results :
 Insert picture description here

js Output inverted right triangle

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>Document</title>
	<script type="text/javascript">
// Type 1 : rectangular 
/*		
		for(var i = 1;i <= 5;i++){
			for(var j = 1;j <= 5;j++){
				document.write("*");
			}
			document.write("<br />");
		}
*/
// Type 2 : Right triangle 
/*
		for(var i = 1;i <= 5;i++){
			for(var j = 1;j <= i;j++){
				document.write("*");
			}
			document.write("<br />");
		}
*/
// Type 3 : An inverted right triangle 
	for(var i = 1;i <= 5;i++){
		for(var j = 5;j >= i;j--){
			document.write("*");
		}
		document.write("<br />");
	}

	</script>
</head>
<body>
	
</body>
</html>

Running results :
 Insert picture description here

原网站

版权声明
本文为[I am the sun?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270720099716.html