41. 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="triangle7()" >Submit</button> </td>
</tr>
</table>
<div id="num"></div>
</body>
<script type="text/javascript">
function triangle7()
{
var n,i,j;
n = parseInt(document.getElementById ("first").value);
for(i = n; i >= 1; i-- )
{
for(j = n; j >= i; j--)
{
document.writeln (j+" ");
}
document.write("</br>");
}
}
</script>
</html>