Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

94
Vistas
I'm trying to create a star pyramid which should contain 1 * in the first row, 2* with equal spaces in the second row, like wise 3rd and 4th row

    [enter image description here][1]

List item

    let x = 4;
    let text = "";
    for(let i = 1; i <= x; i++) {
        for(let j = 1; j <= x - i; j++) {
            text += " ";
        }
        for(let k = 0; k < 2 * i - 1; k++) {
        text += "*";
        }
        text +="\n";
    }
    console.log(text);

---Output I want is like this. I'm new to this. Thank you in advance [1]: https://i.stack.imgur.com/AJvaZ.png

5 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Small change:

let x = 4;
let text = "";
for(let i = 1; i <= x; i++) {
    for(let j = 1; j <= x - i; j++) {
        text += " ";
    }
    text += "*";
    for(let k = 0; k + 1 < i; k++) {
        text += " *";
    }
    text +="\n";
}
console.log(text);
5 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos