Workshop › Chess › Step 29 of 48
undoMove(undo) puts everything back exactly: the moving piece on its start square (a pawn, even after promotion),
the captured piece or '' on the target, and the turn back.
```js
function undoMove(undo) {
const [fr, fc] = undo.m.from
const [tr, tc] = undo.m.to
board[fr][fc] = undo.piece
board[tr][tc] = undo.captured
turn = other(turn)
}
```undo.m.from is the move saved inside undo.makeMove's in reverse; switching turn again gives it back.Under makeMove, leave an empty line and write undoMove.
Skills: Functions
← A move that remembers Only legal moves →