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