Use the minimax algorithm.
Once that is implemented, define a simple heuristic, or evaluation function. It could go something like this:
function scoreBoard(board) {
if(board.isWin()) {
return 1;
}
else if(board.isTie()) {
return 0;
}
else {
return -1;
}
}