Skip to main content

Command Palette

Search for a command to run...

Javascript Chessboard

Published
1 min read
Javascript Chessboard
D

I am a Web Developer from Birtamode 1 Jhapa Nepal. As of 2022 i have 3 years of experience in CSS and 1 year of experience in Javascript + 6 Months of Experince in Node.js

Javascript Chessboard

  • Write a program that creates a string that represents an 8×8 grid.
  • using newline characters to separate lines.
  • At each position of the grid there is either a space or a "#" character.
  • The characters should form a chessboard.
  • Passing this string to console.log should show something like this:
          #  #  #  #
        #  #  #  #
         #  #  #  #
        #  #  #  #
         #  #  #  #
        #  #  #  #
         #  #  #  #
        #  #  #  #
    

    JAVASCRIPT

    let char ="";
    for (let i = 0; i < 4; i++) {
    for (let j = 0; j < 4; j++) {
        if(i%2==0){
            char =char + " " + "#";
        }else{
            char =char + "#" + " ";
        }
    }
    console.log(char);
    char="";
    }
    

More from this blog

D

Dipesh Murmu

46 posts

A Full-Stack Laravel Developer with expertise in HTML, CSS, JavaScript, Tailwind, and core PHP. Leveraging the power of Laravel, I specialize in creating dynamic and responsive web applications.