forked from akshitagit/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhourglass.html
More file actions
36 lines (36 loc) · 1015 Bytes
/
hourglass.html
File metadata and controls
36 lines (36 loc) · 1015 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hourglass Pattern</title>
</head>
<body style="white-space: pre-wrap;font-family: monospace;">
<script>
function hourglass() {
var n = document.getElementById('n').value;
document.write("<body style='white-space: pre-wrap;font-family: monospace;'>");
for(var i=n;i>0;i--) {
document.write(" ".repeat(n-i));
for(var j=i;j>(-1*i)-1;j--) {
document.write(Math.abs(j)+" ");
}
document.write('<br>');
}
document.write(" ".repeat(n)+'0 <br>');
for(var i=1;i<=n;i++) {
document.write(" ".repeat(n-i));
for(var j=i;j>(-1*i)-1;j--) {
document.write(Math.abs(j)+" ");
}
document.write('<br>');
}
document.write('<body>');
}
</script>
<form>
<input autofocus type="number" name="n" id="n"><br>
<button onclick="hourglass()">Print Pattern</button>
</form>
</body>
</html>