-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
122 lines (91 loc) · 2.43 KB
/
index.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
122
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p>scissor paper rock shoot!!</p>
<script type="text/javascript">
//function to generate computers hand//
const win = 'Round won! Ballin!';
const lost = 'Round lost! Sucka';
const tie = 'Draw game! Try again chump';
let pScore = 0;
let cpuScore = 0;
function computerPlay() {
let play = ['r', 'p', 's'];
let choice = play[Math.floor(Math.random()*play.length)];
return choice;
}
function playRound(playerSelection, computerSelection) {
//helper function to change all player inputs lowercase
// resticting accepted entries
const allowedSelections = ["r", "p", "s"];
// allowed selection from player
if (allowedSelections.indexOf(playerSelection) < 0) {
return "Invalid selection"; }
//posible outcomes for the game
if (playerSelection === 'r') {
if (computerSelection === 's') {
return win;
} else if (computerSelection === 'p') {
return lost;
} else {
return tie;
}
}
if (playerSelection === 's') {
if (computerSelection === 'p') {
return win;
} else if (computerSelection === 'r') {
return lost;
} else {
return tie;
}
}
if (playerSelection === 'p') {
if (computerSelection === 'r') {
return win
} else if (computerSelection === 's') {
return lost
} else {
return Tie ;
}
}
};
const playerSelection = prompt('pick: r, p, or s');
const computerSelection = computerPlay();
console.log(playRound(playerSelection, computerSelection));
function game (playRound) {
console.log('You chose:' + playerSelection);
console.log('Overlord chose:' + computerSelection);
console.log(playRound(playerSelection.toLowerCase(), computerSelection));
if (playRound(playerSelection.toLowerCase(), computerSelection) === win) {
pScore++;
}
else if (playRound(playerSelection.toLowerCase(), computerSelection) === lost) {
cpuScore++;
}
else {
pScore;
cpuScore;
}
console.log (pScore + ':' + cpuScore);
}
let i = 0;
for (i; i<= 4; i++) {
game();
}
if (pScore > cpuScore) {
console.log('Game oveer. You Win!');
}
else if(cpuScore > pScore) {
console.log('Game over. Overlord lost');
}
else {
console.log('Game over. Draw Game..');
}
</script>
</body>
</html>