Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function chessBoard(num) {
- if (num > 0) {
- console.log('<div class="chessboard">');
- }
- for (let i = 1; i <= num; i++) {
- console.log(' <div>');
- for (let y = 1; y <= num; y++) {
- if (i % 2 != 0) {
- if (y % 2 != 0) {
- console.log(' <span class="black"></span>');
- } else {
- console.log(' <span class="white"></span>');
- }
- } else {
- if (y % 2 != 0) {
- console.log(' <span class="white"></span>');
- } else {
- console.log(' <span class="black"></span>');
- }
- }
- }
- console.log(' </div>');
- }
- if (num > 0) {
- console.log('</div>');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment