Friday, October 23, 2015

Floyd's Triangle in JavaScript

A simple program that I wrote the will generate the Floy'ds Triangle using JavaScript.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<head>
  <title>Floyd's Triangle </title>
</head>
<style>
h3 {
   font-family:arial;
   };
 </style>
<body>
  <script>
    
    var rows=0, number = 1, counter=0, j=0;
var num_value = parseInt(prompt("Enter number: "));

document.write("<br>");
document.write("<h3> Floyd's Triagle</h3>");
     for ( counter = 1 ; counter <= num_value; counter++ )
       {
           for ( j = 1 ; j <= counter ; j++ )
           {
                
                document.write("<font face='arial' size='3'>");
                document.write(" " + number + " </font>");
number++;
           }
           document.write("<br>");
       }
      document.write("<h3> End of Program </h3>");
</script>
</body>
</html>


1 comment:

  1. Thank you Jake. I was searching for good and simple programs in JS. Thanks for posting so many of them.

    ReplyDelete