By GokiSoft.com| 19:34 23/10/2023|
Học JS

In tam giá * trong Javascript - in tam giác hình * trong Javascript - in tam giác hình sao trong Javascript BT1604

Sinh ngẫu nhiên 1 số tự nhiên N trong Javascript

Thực hiên in hình tam giác như hình sau

*

* *

* * *

* * * *

* * * * *

Ví dụ: với N = 5

Liên kết rút gọn:

https://gokisoft.com/1604

Bình luận

avatar
hohuy1610@gmail.com [community,C2108L]
2021-11-24 16:31:35



https://github.com/HoGiaHuy2003/C2108L-HTML-CSS-JS/tree/master/day-8/bt1604


#index.html


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        var N
        var x
        var y
        N = prompt(`Enter N`)
    for (y = 1; y <= N; y++){   
        document.write(`<br>`) 
        for (x = 1; x <= y; x++){        
        document.write(`*`)
        }
    }
    </script>
</body>
</html>


avatar
hieuvm0512 [community,C2010L]
2021-02-26 11:18:30



<!DOCTYPE html>
<html>
<head>
	<title>Sinh So Ngau Nhien</title>
	<meta charset="utf-8">
</head>
<body style="align-content: center;">
	<h1>Tam Giac hinh sao ngau nhien</h1>
	<script type="text/javascript">
		var n = Math.floor(Math.random()*100)
for(var i = 0; i<n;i++)
{
	for(var j = 0;j<i-1;j++)
	{
document.write('*')
}
document.write('<br/>')
}
	</script>


</body>
</html>


avatar
Nguyễn Minh Hiếu [community,C2010L]
2021-02-23 14:17:24



var n = parseInt(prompt('Nhập n:'));
for(var i=1;i<= n; i++)
{
    for(var j=1;j<= i; j++)
    {
       document.write('*');
    }
    document.write('<br/>');
}


avatar
Đào Mạnh Dũng [community,C2010L]
2021-02-23 13:41:15



<!DOCTYPE html>
<html>
<head>
	<title>Sinh số ngẫu nhiên</title>
</head>
<body>
	
	<h2> tam giá * trong Javascript </h2>
		<br>
			<br>
			
<script type="text/javascript">

	var n = Math.random()*30 + 1;

	for (var i = 1; i <= n; i++) {
		 
		 for (var j = i - 1; j >= 0; j--) {

		 	document.write('*')

		 }
		 		document.write('<br>')
	}
</script>
	

</body>
</html>


avatar
Vũ Trung Kiên [C2009I]
2021-02-03 14:23:07


#1604.html


<!DOCTYPE html>
<html>
<head>
	<title>Vẽ tam giác</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
	<style type="text/css">
		*
		{
			padding: 0;
			margin: 0;
			text-align: center;
		}
		.Main
		{
			border: solid 1px #359ee8;
			border-radius: 10px;
			margin-top: 10px;
		}
		.Top
		{
			border-top-left-radius: 8px;
			border-top-right-radius: 8px;
			background-color: #359ee8;
			padding: 5px 0;
			color: white;
		}
		.BTN
		{
			padding: 15px 25px;
  			outline: none !important;
  			color: #fff;
  			background-color: #359ee8;
  			border: none;
  			border-radius: 15px;
  			box-shadow: 0 9px #999;
  			margin: 10px 0;
		}
		.BTN:hover
		{
			background-color: #2578b3 !important;
		}
		.BTN:active
		{
			background-color: #359ee8;
  			box-shadow: 0 5px #666;
  			transform: translateY(4px);
		}
		.Bot
		{
			margin: 10px 0;
		}
		.Bet
		{
			margin: 5px 0;
		}
	</style>
</head>
<body>
	<div class="container">
		<div class="Main">
			<div class="Top">
				<h4>
					In tam giác
				</h4>
			</div>
			<div class="Bet">
				N = <span id="N">?</span>
			</div>
			<div class="Bot">
				<span id="Show"></span>
				<button class="BTN" type="button" onclick="EnterN()">Nhập giá trị</button>
				<button class="BTN" type="button" style="background-color: green" onclick="Print()">In</button>
				<button class="BTN" type="button" onclick="Del()">Xóa</button>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		function EnterN () {
			n = prompt('Nhập giá trị N:');
			document.getElementById('N').innerHTML = n;
		}
		function Print () {
			for (i = 1; i <= n; i++){
				for (e = 1; e <= i; e++){
					document.getElementById('Show').innerHTML += '* ';
				}
				document.getElementById('Show').innerHTML += '<br>';
			}
		}
		function Del () {
			document.getElementById('Show') .innerHTML = '';
		}
	</script>
</body>
</html>


avatar
silentvoice [C2009I]
2020-12-17 07:03:17

https://phamngoclong.herokuapp.com/baitaplab6/bai4/bai4.html


avatar
Lê Trọng Nghĩa [community,C2009I]
2020-12-17 02:47:44



<!DOCTYPE html>
<html>
<head>
	<title>Thuc hien in hinh tam giac nhu hinh sau</title>
	<meta charset="utf-8">
</head>
<body>
	<script type="text/javascript">
		a = prompt("Nhap N = ")
		for(i = 1; i <= a;i++){
			for(e = 1;e <= i;e++){
				document.write('* ')
			}
			document.write('<br>')
		}
	</script>
</body>
</html>


avatar
nguyen hoang viet [community,C2009I]
2020-12-16 17:28:03

https://nguyenhoangviet.herokuapp.com/in_tam_giac.html

avatar
Pham Tuan Anh [community,C2009I]
2020-12-16 17:02:00


#intamgiac.html


<!DOCTYPE html>
<html>
<head>
	<title>In tam giac</title>
	<meta charset="utf-8">
</head>
<body>
	<script type="text/javascript">
		var n = prompt('Nhap gia tri:')
		for (var i = 1; i <= n; i++){
			for (var j = 0; j < i; j++){
				document.write(" * ")
			}document.write("<br>")
		}
	</script>

</body>
</html>


avatar
Vũ Trung Kiên [C2009I]
2020-12-15 15:35:54


#InTamGiac.html


<!DOCTYPE html>
<html>
<head>
	<title>In Tam Giác</title>
	<meta charset="utf-8">
</head>
<body>
	<script type="text/javascript">
		n = prompt('Nhập N = ')
		for (i = 1; i <= n; i++)
		{
			for (e = 1; e <= i; e++)
			{
				document.write('* ')
			}
			document.write('<br>')
		}
	</script>
</body>
</html>