-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
117 lines (106 loc) · 3.48 KB
/
script.js
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
const GameOptions = ['Rock', 'Paper', 'Scissors'];
//setting the players choice functions
function getComputerChoice() {
let i = Math.floor(Math.random() * 3);
return GameOptions[i];
};
//transforming the values from funtions to variables
var ComputerSelection = "";
// var PlayerSelection = getPlayerChoice();
var PlayerSelection = "";
//setting win varables
var ComputerWins = 0;
var PlayerWins = 0;
function playerwins() {
let poop = "";
for (let i = PlayerWins; i > 0; i--) {
poop = poop + "X ";
};
return poop;
};
function computerwins() {
let poop = "";
for (let i = ComputerWins; i > 0; i--) {
poop = poop + "X ";
};
return poop;
};
//play function sees what the players chose and sees who wins
//I loweredcased everything (I didnt need to)
function play(cpu, human) {
cpu = cpu.toLowerCase();
human = human.toLowerCase();
if (cpu === human) {
document.getElementById("change").innerHTML = "You both chose " + ComputerSelection + ", try again!";
} else if (human === "rock") {
if (cpu === "paper") {
document.getElementById("change").innerHTML = "The CPU chose Paper so you lost!!!";
ComputerWins++;
computerwins()
CheckWins()
return ComputerWins;
} else {
document.getElementById("change").innerHTML = "The CPU chose Scissors so you won!!!";
PlayerWins++;
playerwins();
CheckWins()
return PlayerWins;
};
} else if (human === "paper") {
if (cpu === "scissors") {
document.getElementById("change").innerHTML = "The CPU chose Scissors so you lost!!!";
ComputerWins++;
computerwins()
CheckWins()
return ComputerWins;
} else {
document.getElementById("change").innerHTML = "The CPU chose Rock so you won!!!";
PlayerWins++;
playerwins();
CheckWins()
return PlayerWins;
};
} else if (human === "scissors") {
if (cpu === "rock") {
document.getElementById("change").innerHTML = "The CPU chose Rock so you lost!!!";
ComputerWins++;
computerwins()
CheckWins()
return ComputerWins;
} else {
document.getElementById("change").innerHTML = "The CPU chose Paper so you won!!!";
PlayerWins++;
playerwins();
CheckWins()
return PlayerWins;
};
};
};
function rock() {
PlayerSelection = "Rock"
ComputerSelection = getComputerChoice();
play(ComputerSelection, PlayerSelection);
};
function paper() {
PlayerSelection = "Paper"
ComputerSelection = getComputerChoice();
play(ComputerSelection, PlayerSelection);
};
function scissors() {
PlayerSelection = "Scissors"
ComputerSelection = getComputerChoice();
play(ComputerSelection, PlayerSelection);
};
function CheckWins() {
document.getElementById("p").innerHTML = "Player: " + playerwins();
document.getElementById("c").innerHTML = "CPU: " + computerwins();
if (ComputerWins === 5 || PlayerWins === 5) {
if (ComputerWins === 5) {
document.getElementById("loss").style.opacity = 1;
document.getElementById("loss").style.zIndex = 1000;
} else {
document.getElementById("win").style.opacity = 1;
document.getElementById("win").style.zIndex = 1000;
};
};
};