Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

patterns 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 += "
";
}
// printing the string
console.log(string);


//result look like
/*

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

*/
Comment

javascript patterns

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 += "
";
}
// printing the string
console.log(string);



/*

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

*/
Comment

javascript patterns

*
   **
  ***
 ****
*****
Comment

PREVIOUS NEXT
Code Example
Javascript :: onclick send to email javascript 
Javascript :: compare objects 
Javascript :: local storage in vanila javascript 
Javascript :: add google analytics to react 
Javascript :: Download Node Module With NPM 
Javascript :: add id to Array of Object 
Javascript :: ** javascript Exponentiation 
Javascript :: pdf to json online 
Javascript :: javaScript setHours() Method 
Javascript :: pattern alphabet and space 
Javascript :: javascript loop over three-dimensional array 
Javascript :: yup string date schema validation 
Javascript :: radio button checked jquery 
Javascript :: document on click not working 
Javascript :: process exit code 
Javascript :: encrypt in js 
Javascript :: button change slider value js 
Javascript :: get element by class name 
Javascript :: Download excel using reactJS 
Javascript :: js maths 
Javascript :: ndjson to json javascript 
Javascript :: how to enable emit on react in vs code 
Javascript :: Adding a Method to a JavaScript Object 
Javascript :: next js styled components classname did not match 
Javascript :: how to find last occurrence comma in a string and replace with value in javascript 
Javascript :: react cdn link 
Javascript :: ${} js 
Javascript :: mod operation in shopify 
Javascript :: extract from a string in javascript 
Javascript :: currentTime(); javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =