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

Add getRoundResults

parent 2931764a
Branches feature/playerScore
No related tags found
No related merge requests found
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}`;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment