# JavaScript Pyramide of Stars Javascript

How could I create Pyramide of Stars that increase every row by 2 like that:

``````*
* * *
* * * * *
* * * * * * *
``````

My currently code:

``````for (var x = 0; x < 5; x++) {
for (var y = 0; y <= x; y = y + 1) {
document.write(" * ");
}
document.write("<br>");
}
``````

It's possible just to increment in your loop by 2.

``````for(var i = 1; i < 20; i += 2) {
console.log( Array(i).fill('*').join(' ') );
}
``````

Otherwise just multiply inside your loop

``````for(var i = 0; i < 10; i++) {
console.log( Array(i*2 + 1).fill('*').join(' ') );
}
``````

You may also need to polyfill Array.fill depending on your target.

Other answers recreate the entire row each time. This solution just extends the row each time to have another star.

``````function pyramid(n) {
let result = '', str = '', add = '*';
for (var i = 0; i < n; i++) {
if (!(i % 2)) result += str + '\n';
}
return result;
}

console.log(pyramid(5));``````

You can do like this.

``````function generate() {
var totalNumberofRows = 5;
var output="";
for (var i = 1; i <= totalNumberofRows; i++) {
for (var j = 1; j <= i; j++) {
if(j==1)
output+="*";
else
output+="     "+ "*" + "     "+ "*";
}
console.log(output);
output="";
}
}
generate()``````

## Knockout mapping - difference between objects and observables in class being mapped to

This is driving me absolutely insane, and I just cannot see what I have done wrong. Please help before I start bibbling and gnawing my colleagues leg off. He doesn't deserve that. I have an object I ...

This is driving me absolutely insane, and I just cannot see what I have done wrong. Please help before I start bibbling and gnawing my colleagues leg off. He doesn't deserve that. I have an object I ...

## How to push props to a new page on button click?

I currently have a table and each cell has a button. Upon clicking the button, based on that particular day (Monday or Tuesday), class (class 1 or class 2), and name (Kev or Josh), how can I push an ...

I currently have a table and each cell has a button. Upon clicking the button, based on that particular day (Monday or Tuesday), class (class 1 or class 2), and name (Kev or Josh), how can I push an ...

## Can I / should I download html5 code within a cordova app?

Lets say I had a HTML5/JS based application that is wrapped in cordova phone gap. Can I have it startup and download additional html5/js files? Basically the app would work with the base files, but ...

Lets say I had a HTML5/JS based application that is wrapped in cordova phone gap. Can I have it startup and download additional html5/js files? Basically the app would work with the base files, but ...

## Disable Enter to submit the form

I have a form with multiple TextBoxes, Textarea and Buttons. By pressing the ENTER in any text box submits the form. So i want to disable the pressing enter only in text boxes and to enable in text-...

I have a form with multiple TextBoxes, Textarea and Buttons. By pressing the ENTER in any text box submits the form. So i want to disable the pressing enter only in text boxes and to enable in text-...

1. disable enter submit form
2. disable enter submit form angular
3. disable enter submit form javascript
4. disable enter submit form jquery
5. disable enter submit
6. disable enter submit form html
7. disable enter submit jquery
8. disable enter submit form react
9. disable enter submit form asp.net
10. disable enter submit angular
11. disable submit enter key
12. html disable enter submit
13. disable enter key submit form
14. input disable enter submit
15. js disable enter submit
16. formik disable enter submit
17. javascript disable enter submit
18. disable press enter submit form
19. rails disable enter submit
20. mvc disable enter submit
1