Search
 
SCRIPT & CODE EXAMPLE
 

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, '*')
Comment

PREVIOUS NEXT
Code Example
Javascript :: api integration for web pages in next js 
Javascript :: javascript canvas load image 
Javascript :: assign values to array in javascript 
Javascript :: multiple path names for a same component in react router 
Javascript :: javascript number() method 
Javascript :: what is let js 
Javascript :: Liquid shopify 
Javascript :: js get smallest value of array 
Javascript :: react -native-config 
Javascript :: javascript advanced concepts 
Javascript :: how to clear nodejs terminal in vs code 
Javascript :: discord js role giver 
Javascript :: self invoking function in javascript 
Javascript :: callbacks in jquery 
Javascript :: id in class selector jquery 
Javascript :: js check for obj property 
Javascript :: how to add data modal target attribute in jquery 
Javascript :: automated email sending using node js server 
Javascript :: Dynamically load JS inside JS 
Javascript :: event listener js keydown not working 
Javascript :: define conastant js 
Javascript :: KeyboardDatePicker background color 
Javascript :: mock anonymous function jest 
Javascript :: js arrotondare superiore numero 
Python :: django EMAIL_BACKEND console 
Python :: how to make a resizable pygame window 
Python :: get the current year in python 
Python :: get gpu device name tensorflow 
Python :: how to make pyautogui faster 
Python :: python sigmoid function 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =