JavaScript Basic:Write a JavaScript program to construct a pattern using a ested loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Doctor Ntungwa
    New Member
    • Jun 2017
    • 1

    JavaScript Basic:Write a JavaScript program to construct a pattern using a ested loop

    Write a JavaScript program to construct the following pattern, using a nested for loop.
    * *
    * *
    * *
  • vinit144
    New Member
    • Jun 2017
    • 6

    #2
    Hey, the following code should be helpful.

    Code:
    var x,y,chr;
    for(x=1; x<=3; x++)
    {
      chr='';
       for (y=1; y<=2; y++)
         {
        chr=chr+("*");        
          }
     console.log(chr);   
    }
    The 'i' loop manages the Row, that is, it changes line when required number of '*' are displayed.

    The 'j' loop manages how many '*' are displayed per line. Here each iteration of the 'j' loop adds one '*' to the output.

    Comment

    Working...