diff --git a/game/index.js b/game/index.js index 7609ac02fb9c30a6a1ecc9fd98340001c1bf87e3..24348cb8d189f89873986daa068be04ffd02e0ce 100644 --- a/game/index.js +++ b/game/index.js @@ -1,4 +1,6 @@ const options = ["Stein", "Papier", "Schere"]; +let playerScore = 0; +let computerScore = 0; function getRandomComputerResult(){ const number = Math.floor(Math.random()*options.length); @@ -13,4 +15,16 @@ function hasPlayerWonTheRound(player, computer){ } } -console.log(hasPlayerWonTheRound("Stein", "Schere")); \ No newline at end of file +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}`; + } +}