Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
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

about 4 years 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);
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda