Skip to content
Snippets Groups Projects
Commit a2880211 authored by Sophia Bernert's avatar Sophia Bernert
Browse files

Add getRoundResults

parent 2931764a
No related branches found
No related tags found
No related merge requests found
const options = ["Stein", "Papier", "Schere"]; const options = ["Stein", "Papier", "Schere"];
let playerScore = 0;
let computerScore = 0;
function getRandomComputerResult(){ function getRandomComputerResult(){
const number = Math.floor(Math.random()*options.length); const number = Math.floor(Math.random()*options.length);
...@@ -13,4 +15,16 @@ function hasPlayerWonTheRound(player, computer){ ...@@ -13,4 +15,16 @@ function hasPlayerWonTheRound(player, computer){
} }
} }
console.log(hasPlayerWonTheRound("Stein", "Schere")); function getRoundResults(playerChoice){
\ No newline at end of file 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}`;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment