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