Skip to content

Commit b1b18f3

Browse files
Merge pull request akshitagit#44 from ritik-gupta/patch-1
Create triangle_pattern.html
2 parents 60a5e7f + 13344dc commit b1b18f3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Patterns/triangle_pattern.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Triangle Pattern</title>
7+
</head>
8+
<body style="white-space: pre-wrap;font-family: monospace;"></body>
9+
<script>
10+
function trianglePattern(){
11+
let i, space, rows, k=0, count=0, count1=0
12+
rows = document.getElementById('rows').value;
13+
document.write("<body style='white-space: pre-wrap;font-family: monospace;'>");
14+
for(i=1;i<=rows;i++){
15+
for(space=1;space<=rows-i;space++){
16+
document.write('&nbsp;&nbsp;')
17+
count+=1
18+
}
19+
while(k!= (2*i-1)){
20+
if(count<=rows-1){
21+
document.write(i+k)
22+
document.write('&nbsp;')
23+
count+=1
24+
}
25+
else{
26+
count1+=1
27+
document.write(i+k-2*count1)
28+
document.write('&nbsp;')
29+
}
30+
k+=1
31+
}
32+
count1 = 0
33+
count = 0
34+
k = 0
35+
document.write("<br>")
36+
}
37+
document.write('<body>');
38+
}
39+
</script>
40+
<form>
41+
<input autofocus type="number" name="rows " id="rows"><br>
42+
<button onclick="trianglePattern()">Print Pattern</button>
43+
</form>
44+
</body>
45+
</html>

0 commit comments

Comments
 (0)