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