An exercise about the chess queen figure moves
Ths exercise is very much inspired from Queen Attack in JavaScript
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ W _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ B _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
body
in CSStable
and make it has big as possible (but square and… in CSS).black
CSS class with a black background colorcellClicked
which has 3 arguments (rowNum
, columnNum
and event
).Create a function called renderChessboard
which takes the table
element as argument.
tr
) of 8 cells (td
) (columns), you must use DOM for that because…click
event listener which calls the cellClicked
td
) elements (and you should make a variable of its result ;) ).Hint: you can reuse the logic of the matrix exercise code for that.
.highlight td
and td.highlight
selectors and give it a blue inset
box-shadow
(the other parameters are up to you).highlightRow
which takes a rowNum
argument, add a call to the highlightRow
function you just created in your cellClicked
highlightRow
adds the highlight
class to the row element.Hint: have a look at the parentNode
and classList
properties of a DOM element to add a class to the row.
highlightColumn
which takes a columnNum
argument and will add the highlight
class to the cell element.highlightColumn
to your cellClicked
function (if it’s not already done ;) )removeHighlight
which removes all the .highlight
classes in the chessboard table.removeHighlight
at the beginning of the cellClicked
function.Hint: you could use the .querySelectorAll()
method of DOM elements.
highlightDiagonals
which takes a rowNum
and a columnNum
argument and will add the highlight
class to the cell element placed on the diagonals of the rowNum and columnNum.highlightDiagonals
to your cellClicked
function…0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
0 _ x _ _ _ x _ _ 0 x _ _ _ _ _ _ _ 0 _ _ _ _ _ x _ _
1 _ _ x _ x _ _ _ 1 _ x _ _ _ _ _ _ 1 _ _ _ _ x _ _ _
2 _ _ _ C _ _ _ _ 2 _ _ x _ _ _ _ _ 2 _ _ _ x _ _ _ _
3 _ _ x _ x _ _ _ 3 _ _ _ x _ _ _ _ 3 x _ x _ _ _ _ _
4 _ x _ _ _ x _ _ 4 _ _ _ _ x _ _ _ 4 _ C _ _ _ _ _ _
5 x _ _ _ _ _ x _ 5 _ _ _ _ _ x _ _ 5 x _ x _ _ _ _ _
6 _ _ _ _ _ _ _ x 6 _ _ _ _ _ _ x _ 6 _ _ _ x _ _ _ _
7 _ _ _ _ _ _ _ _ 7 _ _ _ _ _ _ _ c 7 _ _ _ _ x _ _ _