-
Subliminal Guy authoredSubliminal Guy authored
index.js 1.10 KiB
const options = ["Stein", "Papier", "Schere"];
let playerScore = 0;
let computerScore = 0;
const playerScoreElement = document.getElementById("player-score")
function getRandomComputerResult(){
const number = Math.floor(Math.random()*options.length);
return options[number];
}
function hasPlayerWonTheRound(player, computer){
if (player === "Stein" && computer === "Schere" || player === "Schere" && computer === "Papier" || player === "Papier" && computer === "Stein"){
return true;
} else {
return false;
}
}
function getRoundResults(playerChoice){
const playerWon = hasPlayerWonTheRound(playerChoice, computerChoice);
if(playerWon){
playerScore++; //playerScore += 1; playerScore = playerScore + 1;
return `Spieler hat gewonnen! ${playerChoice} schlaegt ${computerChoice}`;
} else if (playerChoice === computerChoice){
return `Unentschieden: beide haben ${playerChoice} gewaehlt.`;
} else {
computerScore++;
return `Computer hat gewonnen! ${computerChoice} schlaegt ${playerChoice}`;
}
}
console.log(playerScoreElement)