-14

I want to create two pyramids using for loop in JavaScript and print it in the console as given below:

enter image description here

2
  • 6
    what you have tried so far? Commented Jul 18, 2016 at 12:55
  • Should it be in two divs, a table, or? Commented Jul 18, 2016 at 12:57

1 Answer 1

1

for (var i = 4; i >= 1; i = i - 1) {
  for (var j = 4; j >= i; j = j - 1) {
    document.write(j);
  }
  //i want this to print a new line
  document.write("<br>");
}

Sign up to request clarification or add additional context in comments.

2 Comments

For first triangle try this code
For your second trianle output take third variable c=1 before loop initialisation and print with (print c) and c++

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.