By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,515 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

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

P: 1
Write a JavaScript program to construct the following pattern, using a nested for loop.
* *
* *
* *
Jun 16 '17 #1
Share this Question
Share on Google+
1 Reply


P: 6
Hey, the following code should be helpful.

Expand|Select|Wrap|Line Numbers
  1. var x,y,chr;
  2. for(x=1; x<=3; x++)
  3. {
  4.   chr='';
  5.    for (y=1; y<=2; y++)
  6.      {
  7.     chr=chr+("*");        
  8.       }
  9.  console.log(chr);   
  10. }
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.
Jun 16 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.