-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.html
126 lines (100 loc) · 3.75 KB
/
index2.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
<!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>Rock Paper Scissors</title>
</head>
<body>
</body>
</html>
<script>
let userScore = 0;
let compScore = 0;
let compChoiceInt = 0;
let userChoiceInt = 0;
let compChoice = {Value: ""}
let userChoice = prompt('rock, paper, or scissors?');
if (userChoice == "rock")
userChoiceInt = 0;
else if (userChoice == "paper")
userChoiceInt = 1;
else if (userChoice == "scissors")
userChoiceInt = 2;
compChoiceInt = computerPlay(compChoice);
playGame();
function computerPlay(compChoice){
let choiceNum = Math.floor(Math.random() * 3);
if (choiceNum == 0)
compChoice.Value = "rock";
else if (choiceNum == 1)
compChoice.Value = "paper";
else if(choiceNum == 2)
compChoice.Value = "scissors";
return choiceNum;
}
var compare=function(choice1,choice2){
if(choice1==choice2){
console.log("Tie!");
}
else if(choice1=="rock"){
if(computerPlay=="scissors"){
console.log("Player Wins!");
} else {
console.log("Computer Wins!");
}
}
else if(userChoice==paper){
if(computerPlay=="rock"){
console.log("Player Wins!");
} else {
console.log("Computer Wins!");
}
}
else if(userChoice==scissors){
if(computerPlay=="rock"){
console.log("Computer Wins!");
} else {
console.log("Player Wins!");
}
}
};
function playRound(){
let win_array = [[0, 2, 1],
[1, 0, 2],
[2, 1, 0]];
let result = win_array[userChoiceInt][compChoiceInt];
if (result == 0){
console.log(`Its a tie! You chose ${userChoice.Value} and The computer chose ${compChoice.Value}`);
}
else if (result == 1){
console.log(`You won! You chose ${userChoice.Value} and The computer chose ${compChoice.Value}`);
userScore++;
}
else if (result== 2 ){
console.log( `You lost! You chose ${userChoice.Value} and The computer chose ${compChoice.Value}`);
compScore++;
}
}
function playGame(){
console.log("Choose Rock, Paper, or Scissors");
playRound();
console.log(`Player Score: ${userScore}`);
console.log(`Computer Score: ${compScore}`);
if (userScore == 5){
console.log("You Won the Game! Congrats");
userScore = 0;
compScore = 0;
console.log(`Player Score: ${userScore}`);
console.log(`Computer Score: ${compScore}`);
}
else if (compScore == 5){
console.log("You Lost the game:/ Maybe find something else to do?")
userScore = 0;
compScore = 0;
console.log(`Player Score: ${userScore}`);
console.log(`Computer Score: ${compScore}`);
}
}
</script>