as mention in this article :
Element: setAttribute() method - Web APIs | MDN[
^]
function ADD_ELM( new_tag, id_target , attr , attr_value ){
newElm = document.createElement(" + new_tag + ") ;
newElm.setAttribute( attr , attr_value ) ;
document.getElementById( id_target ).appendChild( newElm ) ;
}
ADD_ELM( "DIV" , "squares_wrapper" , "class" , "square" ) ;
About "Let" statement :
'let' comes in JS with the modern JS, and is equal : 'void' myVar. this var is alive for the scope of the declaration.
let A = 2 ;
is same as :
A = 2 ;
to remove you can do shorter, with an imperative instruction :
function removeSquare(){
Document.getElementsByClassName("square")[0].remove() ;