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
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
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![hohuy1610@gmail.com [community,C2108L]](https://www.gravatar.com/avatar/15e0636181e201af8d78b5d3e072fd0b.jpg?s=80&d=mm&r=g)
hohuy1610@gmail.com
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>
![hieuvm0512 [community,C2010L]](https://www.gravatar.com/avatar/0cacbf21fed14b987a433597d2edc14f.jpg?s=80&d=mm&r=g)
hieuvm0512
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>
![Nguyễn Minh Hiếu [community,C2010L]](https://www.gravatar.com/avatar/cd93ed3dad5ea834fc22cba6a363c9d9.jpg?s=80&d=mm&r=g)
Nguyễn Minh Hiếu
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/>');
}
![Đào Mạnh Dũng [community,C2010L]](https://www.gravatar.com/avatar/6a111fa53fd75dc87034660a8857df16.jpg?s=80&d=mm&r=g)
Đào Mạnh Dũng
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>
![Vũ Trung Kiên [C2009I]](https://www.gravatar.com/avatar/abf994de48c0204239812f8d9a7dcf8c.jpg?s=80&d=mm&r=g)
Vũ Trung Kiên
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>
![silentvoice [C2009I]](https://www.gravatar.com/avatar/9e5d35bff7e4f5191ba44a5e273bd9ca.jpg?s=80&d=mm&r=g)
silentvoice
2020-12-17 07:03:17
https://phamngoclong.herokuapp.com/baitaplab6/bai4/bai4.html
![Lê Trọng Nghĩa [community,C2009I]](https://www.gravatar.com/avatar/1093e836f419101dc96b7e3f6aab4a56.jpg?s=80&d=mm&r=g)
Lê Trọng Nghĩa
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>
![nguyen hoang viet [community,C2009I]](https://www.gravatar.com/avatar/d2766fccea69cebc93358554d1a18e65.jpg?s=80&d=mm&r=g)
nguyen hoang viet
2020-12-16 17:28:03
https://nguyenhoangviet.herokuapp.com/in_tam_giac.html
![Pham Tuan Anh [community,C2009I]](https://www.gravatar.com/avatar/9f51282c60970134131773debb671510.jpg?s=80&d=mm&r=g)
Pham Tuan Anh
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>
![Vũ Trung Kiên [C2009I]](https://www.gravatar.com/avatar/abf994de48c0204239812f8d9a7dcf8c.jpg?s=80&d=mm&r=g)
Vũ Trung Kiên
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>