javascript - This code is not working with console.log but working fine with document.write -
this code supposed show chessboard of 8*8 size , works fine when use document.write
doesn't show same output console.log
. can please explain.
window.onload = function() { var hash = '#'; var size = 8; (var = 0; < size; i++) { (var j = 0; j < size; j++) { if ((i + j) % 2 === 0) { document.write("\xa0"); } else { document.write(hash); } } document.write("<br>"); } }
is want ?
window.onload = function() { var hash = '#'; var size = 8; var string=""; (var = 0; < size; i++) { (var j = 0; j < size; j++) { if ((i + j) % 2 === 0) { string+="\xa0"; } else { string+=hash; } } string+="\n"; } console.log(string); }
Comments
Post a Comment