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

205
Views
My code is not printing star pattern (+) sign instead it is printing blank space, can you explain why?

In this code, I am trying to print Plus(+) sign pattern and i don't know what is wrong with my if else condition can you please explain what is wrong with my if else condition and offers a solution ?

let n=5;

let pattn="";

for(i=0;i<n;i++){

for(j=0;j<n;j++){

if(i==n/2||j==n/2){

pattn+="*";

}else

pattn+=" ";

}pattn+=" \n";

}console.log(pattn);

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

0

let n = 5;
let pattn = "";

for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
        if (i == 2 || j == 2) {
            pattn += "*";
        } else
            pattn += " ";
    }
    pattn += " \n";
}
console.log(pattn);

let n = 5;
let pattn = "";

for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
        if (i == 2 || j == 2) {
            pattn += "*";
        } else
            pattn += " ";
    }
    pattn += " \n";
}
console.log(pattn);

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!