39. JavaScript Program to Print Number triangle.
How does this program work?
- This program is used to print Number Triangle using JavaScript.
Here is the code
<html>
<head>
<title>JavaScript program to print Triangle Pattern</title>
</head>
<body>
<table>
<tr>
<td> <input type="text" name="a" id="first" placeholder="Enter no. of rows"> </td>
</tr>
<tr>
<td> <button onclick="triangle5()" >Submit</button> </td>
</tr>
</table>
<div id="num"></div>
</body>
<script type="text/javascript">
function triangle5()
{
var n,i,j;
n = parseInt(document.getElementById ("first").value);
for(i = 1; i <= n; i++ )
{
for(j = 1; j <= (n-i); j++)
{
document.writeln( i+" ");
}
document.write("</br>");
}
}
</script>
</html>