Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
144 lines (123 loc) · 4.46 KB
/
Copy pathscript.js
File metadata and controls
144 lines (123 loc) · 4.46 KB
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
let win = 0;
let loss = 0;
if(win == 5){
console.log("WIN");
}
else if(loss == 5){
console.log("FALSE");
}
const r = document.getElementById('rock');
r.addEventListener("click", playRPS);
const p = document.getElementById("paper");
p.addEventListener("click", playRPS);
const s = document.getElementById("scissors");
s.addEventListener("click", playRPS);
function getComputerChoice(){
let randomChoice = Math.floor(Math.random()*3);
switch(randomChoice){
case 0:
return 'rock';
break;
case 1:
return 'paper';
break;
case 2:
return 'scissors';
break;
default:
break;
}
}
function playRPS(e){
// e = e.toLowerCase(e);
console.log(e.target.id + " PLAYER");
// console.log(getComputerChoice() + " PC");
let computerSelection = getComputerChoice();
console.log(computerSelection + " PC")
if(e.target.id == "rock"){
if(computerSelection == "rock"){
document.getElementById('results').append("Tie: " + e.target.id + " vs. " + computerSelection)
// return "Tie: " + e.target.id + " vs. " + computerSelection;
}
else if(computerSelection = "paper"){
document.getElementById('results').append("You lose! Paper beats Rock");
loss++;
// return "You lose! Paper beats Rock";
}
else if(computerSelection == "scissors"){
document.getElementById('results').append("You win! Rock beats Scissors");
win++;
// return "You win! Rock beats Scissors";
}
}
else if(e.target.id == "paper"){
if(computerSelection == "paper"){
document.getElementById('results').append("Tie: " + e.target.id + " vs. " + computerSelection)
// return "Tie: " + computerSelection + " vs. " + e.target.id
}
else if(computerSelection =="rock") {
document.getElementById('results').append("You win! Paper beats Rock")
win++;
// return "You win! Paper beats Rock";
}
else if(computerSelection == "scissors"){
document.getElementById('results').append("You lose! Scissors beats Paper")
loss++;
// return "You lose! Scissors beats Paper";
}
}
else{
if(computerSelection == "scissors") {
document.getElementById('results').append("Tie: " + e.target.id + " vs. " + computerSelection)
// return "Tie: Scissors/Scissors";
}
else if(computerSelection == "rock") {
document.getElementById('results').append("You lose! Rock beats Scissors")
loss++;
// return "You lose! Rock beats Scissors";
}
else if(computerSelection == "paper") {
document.getElementById('results').append("You win! Scissors beats Paper")
win++;
// return "You win! Scissors beats Paper";
}
}
console.log("WIN " + win)
console.log("LOSE " + loss)
if(win == 5){
console.log("WIN " + win);
}
else if(loss == 5){
console.log("LOSE " + loss);
}
return;
}
// function playRPS(e){
// window.addEventListener('click', function(e){
// let b = document.querySelectorAll('button');
// console.log(b);
// })
// }
// if(playerSelection == "rock"){
// if(computerSelection == "rock") return "Tie: " + playerSelection + " vs. " + computerSelection;
// else if(computerSelection = "paper") return "You lose! Paper beats Rock";
// else if(computerSelection == "scissors") return "You win! Rock beats Scissors";
// }
// else if(playerSelection == "paper"){
// if(computerSelection == "paper") return "Tie: " + computerSelection + " vs. " + e
// else if(computerSelection =="rock") return "You win! Paper beats Rock";
// else if(computerSelection == "scissors")return "You lose! Scissors beats Paper";
// }
// else{
// if(computerSelection == "scissors") return "Tie: Scissors/Scissors";
// else if(computerSelection == "rock") return "You lose! Rock beats Scissors";
// else if(computerSelection == "paper") return "You win! Scissors beats Paper";
// }
// console.log(c);
// function game(){
// let input;
// for(let i =0; i<5; i++){
// input = prompt("Rock, Paper, or Scissors?");
// console.log(playRPS(input, getComputerChoice()));
// }
// }