Drawing Chess Board(change size variable for different chess board output)

//drawing Chess Board 8 x 8 var size = 10; var initialBlock_left = " #" var initialBlock_right = "# " for (var InitialSize =0; InitialSize <size; InitialSize +=1) { if(InitialSize %2 == 0){ initialBlock_left = " #"; for(var matrix = 0; matrix < size -2 ; matrix +=2){ initialBlock_left += " #"; } console.log(initialBlock_left); //console.log('I am in block 1'); } else { initialBlock_right = "# "; for(var matrix = 0; matrix < size -2 ; matrix +=2){ initialBlock_right += "# "; } console.log(initialBlock_right); //console.log('I am in block 2') } }
An assignment in the 2nd chapter of EloquentJavaScript

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.