“JavaScript -Muster” Code-Antworten

Muster in JavaScript

let n = 5; // row or column count
// defining an empty string
let string = "";

for(let i = 0; i < n; i++) { // external loop
  for(let j = 0; j < n; j++) { // internal loop
    string += "*";
  }
  // newline after each row
  string += "\n";
}
// printing the string
console.log(string);


//result look like
/*

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

*/
Selfish Skylark

JavaScript -Muster

let n = 5; // row or column count
// defining an empty string
let string = "";

for(let i = 0; i < n; i++) { // external loop
  for(let j = 0; j < n; j++) { // internal loop
    if(i === 0 || i === n - 1) {
      string += "*";
    }
    else {
      if(j === 0 || j === n - 1) {
        string += "*";
      }
      else {
        string += " ";
      }
    }
  }
  // newline after each row
  string += "\n";
}
// printing the string
console.log(string);



/*

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

*/
Selfish Skylark

JavaScript -Muster

*
   **
  ***
 ****
*****
Selfish Skylark

Muster in JavaScript

*****
*****
*****
*****
*****
Wicked Worm

Ähnliche Antworten wie “JavaScript -Muster”

Fragen ähnlich wie “JavaScript -Muster”

Weitere verwandte Antworten zu “JavaScript -Muster” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen