Ad

why not

Code
Diff
  • function rps(player1, player2) {
      const rules = {
        'rock': {
          killer: 'paper'
        },
        'paper': {
          killer: 'scissors'
        },
        'scissors': {
          killer: 'rock'
        },
      };
    
      if (rules[player1].killer === player2) {
        return 'Player 2 won!';
      }
      
      if (rules[player2].killer === player1) {
        return 'Player 1 won!';
      }
      
      return 'Draw!';
    }
    
    • function rps(player1, player2) {
    • return player1 == player2 ? 'Draw!' :
    • player1 == 'rock' && player2 == 'scissors' ||
    • player1 == 'scissors' && player2 == 'paper' ||
    • player1 == 'paper' && player2 == 'rock' ? 'Player 1 won!' : 'Player 2 won!';
    • const rules = {
    • 'rock': {
    • killer: 'paper'
    • },
    • 'paper': {
    • killer: 'scissors'
    • },
    • 'scissors': {
    • killer: 'rock'
    • },
    • };
    • if (rules[player1].killer === player2) {
    • return 'Player 2 won!';
    • }
    • if (rules[player2].killer === player1) {
    • return 'Player 1 won!';
    • }
    • return 'Draw!';
    • }