Skip to content

Tic Tak Toe Game is Missing a case which makes O a winner in case the game results in a Draw. #49

@heymant09

Description

@heymant09

In the Tic Tak Toe game,
We have a function which checks for a winner, It should include a return false statement in the end.
This missing line of code is resulting in O being declared as a winner in case we have a draw.

URL of the file : https://github.com/shradha-khapra/JavaScriptSeries/tree/main/TicTacToe/app.js

Updated function with correct logic :

const checkWinner = () => {
for (let pattern of winPatterns) {
let pos1Val = boxes[pattern[0]].innerText;
let pos2Val = boxes[pattern[1]].innerText;
let pos3Val = boxes[pattern[2]].innerText;

if (pos1Val != "" && pos2Val != "" && pos3Val != "") {
  if (pos1Val === pos2Val && pos2Val === pos3Val) {
    showWinner(pos1Val);
    return true;
  }
}

}
return false;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions