Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.5 kB
2
Indexable
Never
let playerScore=0;
let computerScore=0;
let roundWinner = ''

function computerPlay() {
    const fighter = ["Rock", "Paper", "Scissors"];
    const computerSelection = fighter[Math.floor(Math.random() * fighter.length)];
    return computerSelection;
}

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

    if (playerSelection === computerSelection) {
        return ("It's a tie!")
    } 
    else if (
        (playerSelection === "paper" && computerSelection === "rock") ||
        (playerSelection === "rock" && computerSelection === "scissors") ||
        (playerSelection === "scissors" && computerSelection === "paper")
    ) {
        playerScore++
        return ("You won " + playerSelection + " beats " + computerSelection + "!")
        
    }
    else if (
        (computerSelection === "paper" && playerSelection === "rock") ||
        (computerSelection === "rock" && playerSelection === "scissors") ||
        (computerSelection === "scissors" && playerSelection === "paper")
    ) {
        computerScore++
        return ("You lost " + computerSelection + " beats " + playerSelection + "!")
    }    
}


function game() {
    playRound(playerSelection, computerSelection) 
        return ("Player score is" + playerScore, "Computer score is " + computerScore)
    }


const playerSelection = "rock";
const computerSelection = computerPlay();
console.log(game())