Right Triangle Star Pattern Program

Right Triangle Star Pattern Program

February 10, 2023


Learn How to make Right Triangle Star Pattern Program in JavaScript

today I'm going to teach you how to make Right Triangle Star Program using JavaScript.

  • We need to make three loops for this.
  • The first loop is the main loop deciding how many rows we want.
  • The remaining two loops will be inside the first loop.
  • the second loop will be to print the empty space
  • The third and last loop for how many columns we want.

Add Javascript Code In Your File:

Example:

var x = 5;
for (let i = 1; i <= x; i++) { // first loop for rows
  
  	for(let k=1; k <= 5-i; k++){ //second loop for empty space
      document.write("&nbsp;&nbsp;"); // &nbsp; is HTML Entity to use for empty space. we are use two time &nbsp; because 1 character(size) = 2 space(size) 
    }
    for (let j = 1; j <= i; j++) { // third loop for columns
        document.write("*"); // print *
    }
    document.write("<br/>"); //print line break
}
Try this code