-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
42 lines (40 loc) · 1.23 KB
/
code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
function getComputerChoice(){
choice="nothing";
randnum=getRandomInt(3);
if(randnum=0){choice="Schere";}
if(randnum=1){choice="Stein";}
if(randnum=2){choice="Papier";}
return choice;
}
function playRound(playerSeletion,computerSelection){
winner="error";
if(playerSeletion=="Schere"){
if(computerSelection=="Schere"){winner="noone"}
if(computerSelection=="Stein"){winner="computer"}
if(computerSelection=="Papier"){winner="player"}
}
if(playerSeletion=="Stein"){
if(computerSelection=="Schere"){winner="player"}
if(computerSelection=="Stein"){winner="noone"}
if(computerSelection=="Papier"){winner="computer"}
}
if(playerSeletion=="Papier"){
if(computerSelection=="Schere"){winner="computer"}
if(computerSelection=="Stein"){winner="player"}
if(computerSelection=="Papier"){winner="noone"}
}
return winner;
}
function game(){
console.log("Schere Stein Papier");
console.log("Was wählst du?");
playersel=prompt();
winner=playRound(playersel,getComputerChoice());
console.log("Du hast "+ playersel +" gewählt. Der computer wählte " +getComputerChoice());
console.log(winner +" won!");
}
for (let i=0;i<5;i++){
game();}