📅  最后修改于: 2022-03-11 15:01:47.385000             🧑  作者: Mango
// 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 += '\n';
}
// overriding element value with the generated string
element.innerHTML = string;
}
// using the function
makeSquare(document.querySelector('#square'), 5, '*')