-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
148 lines (116 loc) · 5.83 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function computerPlay(){
var x = Math.floor((Math.random() * 3) + 1);
var arrayIndex = (x - 1);
const array = ["ROCK", "PAPER", "SCISSORS"];
return array[arrayIndex];
}
function input(){
var choice;
return choice = window.prompt("Rock | Paper | Scissors");
}
let computerSelection = computerPlay();
function game(){
const Rounds = 5;
var compterScore = 0;
var playerScore = 0;
var j=1;
for( j; j<= Rounds; j++){
var playerSelection = input();
computerSelection = computerPlay();
/*If Statements to Get scores when game is Draw, Get scores for playerSelection and get scores for computerSelection. */
/*Get score when game Round is DRAW!*/
if(playRound(playerSelection, computerSelection) === "Draw game " + playerSelection + " cannot beat "+ computerSelection){
compterScore = compterScore + 0;
playerScore = playerScore + 0;
console.log("Draw game " + playerSelection + " cannot beat "+ computerSelection);
}
/*GET SCORE WHEN COMPUTER WINS */
if(playRound(playerSelection, computerSelection) === "You loose "+ computerSelection + " beats " + playerSelection){
compterScore = compterScore + 1;
console.log("You loose "+ computerSelection + " beats " + playerSelection);
}
/*GET SCORE WHEN PLAYER WINS*/
if(playRound(playerSelection, computerSelection) === "You have won "+ playerSelection + " beats " + computerSelection)
{
playerScore = playerScore + 1;
console.log("You have won "+ playerSelection + " beats " + computerSelection);
}
/*To display who has won what round*/
if(compterScore > playerScore){
console.log("The computer has won you Round " +j);
}
if(playerScore > compterScore){
console.log(" You have won the computer Round " +j);
}
if(compterScore === playerScore)
console.log(" You have drawn with computer Round "+j);
}
/*To return the final result of the game*/
if(playerScore === compterScore)
return "It's a Draw!!! You've played five Rounds of the Rock, Paper, Scissors Game. You have drawn with computer. PRESS Ctrl + R to load a new game.";
if(playerScore > compterScore)
return "Congratulations!!!! You've played five Rounds of the Rock, Paper, Scissors Game. You have won the computer. PRESS Ctrl + R to load a new game.";
if(compterScore > playerScore)
return "Sorry!! You've played five Rounds of the Rock, Paper, Scissors Game. The computer has won. PRESS Ctrl + R to load a new game.";
}
/*Function to decide the winner of each round.*/
function playRound(playerSelection, computerSelection)
{
/*Statements of a draw game*/
if(playerSelection.toUpperCase() === "ROCK" && computerSelection === "ROCK")
{
return "Draw game " + playerSelection + " cannot beat "+ computerSelection;
}
if(playerSelection.toUpperCase() === "PAPER" && computerSelection === "PAPER")
{
return "Draw game " + playerSelection + " cannot beat "+ computerSelection;
}
if(playerSelection.toUpperCase() === "SCISSOR" && computerSelection === "SCISSOR")
{
return "Draw game " + playerSelection + " cannot beat "+ computerSelection;
}
/*End of draw game statements*/
/*Decisions for Rock*/
if(playerSelection.toUpperCase() === "ROCK" && computerSelection === "PAPER")
{
return "You loose "+ computerSelection + " beats " + playerSelection;
}
if(playerSelection.toUpperCase() === "ROCK" && computerSelection === "SCISSOR")
{
return "You have won "+ playerSelection + " beats " + computerSelection;
}
/*End of Rock play Decsisions*/
/*Decisions for paper*/
if(playerSelection.toUpperCase() === "PAPER" && computerSelection === "ROCK")
{
return "You have won "+ playerSelection + " beats " + computerSelection ;
}
if(playerSelection.toUpperCase() === "PAPER" && computerSelection === "SCISSOR")
{
return "You loose "+ computerSelection + " beats " + playerSelection;
}
/*End of Paper play Decision*/
/*Decision for Scissors*/
if(playerSelection.toUpperCase() === "SCISSOR" && computerSelection === "ROCK")
{
return "You loose "+ computerSelection + " beats " + playerSelection;
}
if(playerSelection.toUpperCase() === "SCISSOR" && computerSelection === "PAPER")
{
return "You have won "+ playerSelection + " beats " + computerSelection;
}
}
console.log(game());
</script>
</body>
</html>