With below Javascript code you can easily create triangle pattern.
Just add number inside diamond() function.
Just add number inside diamond() function.
<html> <head> <title>Triangle Pattern</title> </head> <body> <script type = "text/javascript"> function triangles(n) { n = Math.floor(n); document.write("<pre>"); for (var i = 1; i <= n; i++) { for (var k = 1; k <= i; k++) { document.write("*"); } document.write("<br>"); } document.write("<br>"); for (var i = n; i >= 1; i--) { for (var k = i; k >= 1; k--) { document.write("*"); } document.write("<br>"); } document.write("</pre>"); } triangles(10); // 10 is number of rows in triangle </script> </body> </html>
0 Comments