• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

154
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

almost 3 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);
almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda