Rock Paper Scissors game- JavaScript This is a console version of the famous Rock Paper Scissors game part of The Odin Project curriculum. Please review this code and provide suggestions. Please comment whether the code is DRY and if it is simplified.



function computerPlay() {
    let choices = ['rock', 'paper', 'scissors'];
    return choices[Math.floor(Math.random() * choices.length)];
}

function playRound(playerSelection, computerSelection) {
    const capitalize = word =&gt; { return word.charAt(0).toUpperCase() + word.slice(1); }
    const winStatement = (winner, loser) =&gt; { return `You Win! ${capitalize(winner)} beats ${capitalize(loser)}`; }
    const loseStatement = (winner, loser) =&gt; { return `You Lose! ${capitalize(winner)} beats ${capitalize(loser)}`; }
    const winningChoice = {'rock': 'paper', 'paper': 'scissors', 'scissors': 'rock'};
    
    playerSelection = playerSelection.toLowerCase();
    
    if(playerSelection === computerSelection) return "Oh! It's a tie";
    else if(playerSelection === winningChoice[computerSelection]) return winStatement(playerSelection, computerSelection);
    else return loseStatement(computerSelection, playerSelection);
}

const playerSelection = 'rock';
const computerSelection = computerPlay();
console.log(playRound(playerSelection, computerSelection));
All in all, a basic review of your question shows that you are creating objects numerous times, when they do not need to be. Other things are pointed out in comments.

const choices = ['rock', 'paper', 'scissors'],
      capitalize = word =&gt; word.charAt(0).toUpperCase() + word.slice(1),
      // Should these be made into 1 function, that takes another argument, 'condition', which is 'Win' or 'Lose'?
      winStatement = (winner, loser) =&gt; `You Win! ${capitalize(winner)} beats ${capitalize(loser)}`,
      loseStatement = (winner, loser) =&gt; `You Lose! ${capitalize(winner)} beats ${capitalize(loser)},
      winningChoice = {'rock': 'paper', 'paper': 'scissors', 'scissors': 'rock'};

function computerPlay() {
    return choices[Math.floor(Math.random() * choices.length)];
}

function playRound(playerSelection, computerSelection) {
    playerSelection = playerSelection.toLowerCase();

    // Also, Consecutive if statements that all return need not be else-if.
    if(playerSelection === computerSelection) {
        return "Oh! It's a tie";
    }
    if(playerSelection === winningChoice[computerSelection]) {
        return winStatement(playerSelection, computerSelection);
    }
    return loseStatement(computerSelection, playerSelection);
}

// Should be improved upon? Actually take input?
const playerSelection = 'rock';
const computerSelection = computerPlay();
console.log(playRound(playerSelection, computerSelection));