Print Star Pattern in JavaScript
Advertisements
Print Star Pattern in JavaScript
Using JavaScript we can easily write any programming code, Here we write one of the most popular program Print Star Pattern in JavaScript. To perform this task we need for loop. In JavaScript we use document.write() function to print * on screen.
Print Triangle of Stars in JavaScript
<html> <head> <script type="text/javascript"> var i, j; //outer loop for(i=1; i <= 5; i++) { //inner loop for(j=1; j<=i; j++) { document.write('*'); } document.write('<br/>'); } </script> </head> <body> </body> </html>
Output
* ** *** **** *****
Print Triangle of Stars in JavaScript
<html> <head> <script type="text/javascript"> var i, j; //outer loop for(i=5;i>=1;i--) { //inner loop for(j=1;j<=i;j++) { document.write('*'); } document.write('<br/>'); } </script> </head> <body> </body> </html>
Output
***** **** *** ** *
Google Advertisment