Function to alternate players' turns, unless a player has won I am doing a coding challenge and it basically says this. There are two players, "black" and "white" and they take turns at a game. If a player won the last turn then it is his turn again, otherwise it is the other player's turn. The whole challenge is here.

Here is the original code I used for that:

function whoseMove(lastPlayer, win) {
  if (lastPlayer == "white") {
      if (win) {
          return "white";
      }
      return "black";
  } else {
      if (win) {
          return "black";
      }
      return "white";
  }
}


however I realised that this could be simplified by changing it to this:

function whoseMove(lastPlayer, win) {
  if (lastPlayer == "white") {
      return win ? "white" : "black";
  } else {
      return win ? "black" : "white";
  }
}


I wonder if this could be simplified even more? Is it possible to have more than one condition in the conditional return statement (I think that is what it is called)?
You could return the same player if win is true, otherwise return the other player, this is done with only 2 tests:

function whoseMove(lastPlayer, win) {
    if (win) return lastPlayer;
    return lastPlayer == "black" ? "white" : "black";
}