In chess there are total 8 rows, in which at the start, first row (i.e row 0) and last row (i.e row 7) contains all major pieces e.g rook, knight, bishop, queen, king etc.
And row 1 and row 6 contains all pawns.
Note:- Since all entries for row 1 is same so created an array of size 8 filled with same entry.
e.g Array(3).fill(“xyz”) will result [“xyz”, “xyz”, “xyz”]
It creates 8 rows and for each rows 8 cols. It assigned a class “even” or “odd” so that the squared boxes would be coloured differently. And also set the chess pieces for corresponding rows.
Step 5. Add styling in styles.css file
Complete logic and jsx are written within the App.js file which included styles.css file containing all board styling.
chess board size is kept as 640 px width and height and each square is of size 80px width and height.
Conclusion
This app consists only the chessboard design but we can add logic to make it basic version of chess application. It can also be developed using the vanilla js and optimised css but I wanted to try out in react and written in my own way.
I hope you would have learned something new, please share the articles among your friends.