Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
programa para imprimir el patrón 'Cuadrado' en javascript

Intenté imprimir el programa de patrón de 3 * 5 cuadros * (estrella), pero no pude lograr que se formateara correctamente. ¿Puede alguien guiarme si hay errores y ayudar a rectificar?

A continuación se muestra el código javascript:

 // Getting input via STDIN const readline = require("readline"); const inp = readline.createInterface({ input: process.stdin }); const userInput = []; inp.on("line", (data) => { userInput.push(data); }); inp.on("close", () => { //start-here var i,j,a=3,b=5; for(i=1;i<=a;i++) { for(j=1;j<=b;j++) { console.log("*"); } console.log("\n"); } //end-here });

producción:

 * * * * * * * * * * * * * * *

necesita obtener esta salida:

 ***** ***** *****
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

console.log se registra automáticamente en una nueva línea. En su lugar, debe agregar una variable y registrarla fuera del bucle:

 var i, j, a = 3, b = 5; for (i = 1; i <= a; i++) { var str = ""; for (j = 1; j <= b; j++) { str += "*"; } console.log(str + "\n"); }

O incluso mejor, no use un bucle en absoluto y use String.repeat :

 var i, j, a = 3, b = 5; for (i = 1; i <= a; i++) { console.log("*".repeat(b) + "\n"); }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!