Untitled

 avatar
unknown
javascript
2 years ago
2.1 kB
9
Indexable
function rockPaperCissors() {
    let playerRound = 5;
    const computerSelection = getComputerChoice();
    const playerSelection = getPlayerChoice();

    while (playerRound > 0){

        if (computerSelection === playerSelection){
            console.log(`Vous avez choisi ${playerSelection} et l'ordinateur a choisi ${computerSelection}. C'est donc un match nul.`);
            playerRound = playerRound - 1;
        } else if (computerSelection === "pierre" && playerSelection === "ciseaux") {
            console.log(`Vous avez choisi ${playerSelection} et l'ordinateur a choisi ${computerSelection}. Vous avez perdu.`);
            playerRound = playerRound - 1;
        } else if (computerSelection === "pierre" && playerSelection === "papier") {
            console.log(`Vous avez choisi ${playerSelection} et l'ordinateur a choisi ${computerSelection}. Vous avez gagné.`);
            playerRound = playerRound - 1;
        }else if (computerSelection === "papier" && playerSelection === "pierre"){
            console.log(`Vous avez choisi ${playerSelection} et l'ordinateur a choisi ${computerSelection}. Vous avez perdu.`);
            playerRound = playerRound - 1;
        }else if (computerSelection === "papier" && playerSelection === "ciseaux"){
            console.log(`Vous avez choisi ${playerSelection} et l'ordinateur a choisi ${computerSelection}. Vous avez gagné.`);
            playerRound = playerRound - 1;
        }else if (computerSelection === "ciseaux" && playerSelection === "papier"){
            console.log(`Vous avez choisi ${playerSelection} et l'ordinateur a choisi ${computerSelection}. Vous avez perdu.`);
            playerRound = playerRound - 1;
        }else if (computerSelection === "ciseaux" && playerSelection === "pierre"){
            console.log(`Vous avez choisi ${playerSelection} et l'ordinateur a choisi ${computerSelection}. Vous avez gagné.`);
            playerRound = playerRound - 1;
        }
}   if (playerRound === 0) {
    let replay = prompt("Voulez-vous rejouer ?", "Y/N");
        if (replay === "Y") {
            rockPaperCissors();
        }
}
}
Editor is loading...