-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock_paper_scissors.html
121 lines (94 loc) · 3.95 KB
/
rock_paper_scissors.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script>
const computerSelection = computerPlay();
let playerSelection;
function computerPlay() {
let randomInt = Math.floor(Math.random() * 100);
if (randomInt <= 33) {
return 'Rock';
} else if (randomInt <= 66) {
return 'Paper';
} else {
return 'Scissors';
}
}
let whoWins = function playRound(playerSelection, computerSelection) {
if (playerSelection.toLowerCase() === computerSelection.toLowerCase()) {
return "It's a tie, nobody gets any points!";
} else if (playerSelection.toLowerCase() === 'rock' && computerSelection == 'Paper') {
return 'You loose, Paper beats Rock!';
} else if (playerSelection.toLowerCase() === 'rock' && computerSelection == 'Scissors') {
return 'You win, Rock beats Scissors!';
} else if (playerSelection.toLowerCase() === 'paper' && computerSelection == 'Rock') {
return 'You win, Paper beats Rock!';
} else if (playerSelection.toLowerCase() === 'paper' && computerSelection == 'Scissors') {
return 'You loose, Scissors beat Paper!';
} else if (playerSelection.toLowerCase() === 'scissors' && computerSelection == 'Paper') {
return 'You win, Scissors beat Paper!';
} else if (playerSelection.toLowerCase() === 'scissors' && computerSelection == 'Rock') {
return 'You loose, Rock beats Scissors!';
} else {
return 'You need to pick one to play!';
}
}
function game(){
let pointsPlayer = 0;
let pointsComputer = 0;
playerSelection = prompt('Rock, Paper or Scissors? Pick one!');
let round = whoWins(playerSelection, computerSelection)
console.log(round);
if (round.indexOf('win') !== -1) {
pointsPlayer += 1;
} else if (round.indexOf('loose') !== -1) {
pointsComputer += 1
}
console.log('You have ' + pointsPlayer + ' points, Computer has ' + pointsComputer + ' points.' )
// HÄR BÖRJAR SPELRUNDA 2
playerSelection = prompt('Rock, Paper or Scissors? Pick one!');
round = whoWins(playerSelection, computerSelection)
console.log(round);
if (round.indexOf('win') !== -1) {
pointsPlayer += 1;
} else if (round.indexOf('loose') !== -1) {
pointsComputer += 1
}
console.log('You have ' + pointsPlayer + ' points, Computer has ' + pointsComputer + ' points.' )
// HÄR BÖRJAR SPELRUNDA 3
playerSelection = prompt('Rock, Paper or Scissors? Pick one!');
round = whoWins(playerSelection, computerSelection)
console.log(round);
if (round.indexOf('win') !== -1) {
pointsPlayer += 1;
} else if (round.indexOf('loose') !== -1) {
pointsComputer += 1
}
console.log('You have ' + pointsPlayer + ' points, Computer has ' + pointsComputer + ' points.' )
// HÄR BÖRJAR SPELRUNDA 4
playerSelection = prompt('Rock, Paper or Scissors? Pick one!');
round = whoWins(playerSelection, computerSelection)
console.log(round);
if (round.indexOf('win') !== -1) {
pointsPlayer += 1;
} else if (round.indexOf('loose') !== -1) {
pointsComputer += 1
}
console.log('You have ' + pointsPlayer + ' points, Computer has ' + pointsComputer + ' points.' )
// HÄR BÖRJAR SPELRUNDA 5
playerSelection = prompt('Rock, Paper or Scissors? Pick one!');
round = whoWins(playerSelection, computerSelection)
console.log(round);
if (round.indexOf('win') !== -1) {
pointsPlayer += 1;
} else if (round.indexOf('loose') !== -1) {
pointsComputer += 1
}
console.log('You have ' + pointsPlayer + ' points, Computer has ' + pointsComputer + ' points.' )
// Här räknas poängen samman
if (pointsComputer < pointsPlayer) {
console.log('You win!');
} else if (pointsComputer > pointsPlayer) {
console.log('You loose, Computer wins!');
} else {
console.log('This game is tied!')
}
}
</script>