Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript print square

// make square function
function makeSquare(element, size, character){
  // result string
  var string = '';

  // generating 2D string based on size and character parameter
  for (var i = 0; i < size; i++) {
      for (var j = 0; j < size; j++) {
          string += character;
      }
      string += '
';
  }
  
  // overriding element value with the generated string
  element.innerHTML = string;
}

// using the function
makeSquare(document.querySelector('#square'), 5, '*')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #print #square
ADD COMMENT
Topic
Name
3+6 =