showing results for - "javascript print square"
Emanuele
28 Jan 2020
1// make square function
2function makeSquare(element, size, character){
3  // result string
4  var string = '';
5
6  // generating 2D string based on size and character parameter
7  for (var i = 0; i < size; i++) {
8      for (var j = 0; j < size; j++) {
9          string += character;
10      }
11      string += '\n';
12  }
13  
14  // overriding element value with the generated string
15  element.innerHTML = string;
16}
17
18// using the function
19makeSquare(document.querySelector('#square'), 5, '*')