forked from akshitagit/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangle_pattern.html
More file actions
45 lines (45 loc) · 1.32 KB
/
triangle_pattern.html
File metadata and controls
45 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Triangle Pattern</title>
</head>
<body style="white-space: pre-wrap;font-family: monospace;"></body>
<script>
function trianglePattern(){
let i, space, rows, k=0, count=0, count1=0
rows = document.getElementById('rows').value;
document.write("<body style='white-space: pre-wrap;font-family: monospace;'>");
for(i=1;i<=rows;i++){
for(space=1;space<=rows-i;space++){
document.write(' ')
count+=1
}
while(k!= (2*i-1)){
if(count<=rows-1){
document.write(i+k)
document.write(' ')
count+=1
}
else{
count1+=1
document.write(i+k-2*count1)
document.write(' ')
}
k+=1
}
count1 = 0
count = 0
k = 0
document.write("<br>")
}
document.write('<body>');
}
</script>
<form>
<input autofocus type="number" name="rows " id="rows"><br>
<button onclick="trianglePattern()">Print Pattern</button>
</form>
</body>
</html>