-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockPaperScissor.js
107 lines (99 loc) · 3.86 KB
/
RockPaperScissor.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
var p_count=0;
var c_count=0;
var rock_c ="fas fa-hand-rock";
var paper_c ="fas fa-hand-paper";
var scissor_c = "fas fa-hand-scissors";
// funtion if the player had selected the scissors button
function rock(){
// Radom set of numbers for computers choice
console.log("ROCK HAS BEEN SELECTED");
choice = Math.floor((Math.random() * 3) + 1);
if(choice === 1){
document.getElementById("eva").innerHTML = "DRAW";
document.getElementById("player").className = rock_c;
document.getElementById("computer").className = rock_c;
}
else if(choice === 2){
document.getElementById("eva").innerHTML = "Computer Wins"
document.getElementById("player").className = rock_c;
document.getElementById("computer").className = paper_c;
c_count = c_count +1;
}
else if(choice === 3){
document.getElementById("eva").innerHTML = "You won"
document.getElementById("player").className = rock_c;
document.getElementById("computer").className = scissor_c;
p_count = p_count +1;
}
else{
document.getElementById("eva").innerHTML = "ERROR"
}
document.getElementById("p_score").innerHTML = p_count;
document.getElementById("c_score").innerHTML = c_count;
}
// funtion if the player had selected the scissors button
function paper(){
console.log("PAPER HAS BEEN SELECTED");
// Radom set of numbers for computers choice
choice = Math.floor((Math.random() * 3) + 1);
if(choice === 1){
document.getElementById("eva").innerHTML = "You won"
document.getElementById("player").className = paper_c;
document.getElementById("computer").className = rock_c;
p_count = c_count+1;
}
else if(choice === 2){
document.getElementById("eva").innerHTML = "Draw"
document.getElementById("player").className = paper_c;
document.getElementById("computer").className = paper_c;
}
else if(choice === 3){
document.getElementById("eva").innerHTML = "Computer wins"
document.getElementById("player").className = paper_c;
document.getElementById("computer").className = scissor_c;
c_count = c_count +1;
}
else{
document.getElementById("eva").innerHTML = "ERROR"
}
document.getElementById("p_score").innerHTML = p_count;
document.getElementById("c_score").innerHTML = c_count;
}
// funtion if the player had selected the scissors button
function scissor(){
console.log("SCISSOR HAS BEEN SELECTED");
// Radom set of numbers for computers choice
choice = Math.floor((Math.random() * 3) + 1);
if(choice === 1){
document.getElementById("eva").innerHTML = "Computer wins"
document.getElementById("player").className = paper_c;
document.getElementById("computer").className = rock_c;
c_count = c_count +1;
}
else if(choice === 2){
document.getElementById("eva").innerHTML = "You Won"
document.getElementById("player").className = scissor_c;
document.getElementById("computer").className = paper_c;
p_count = p_count +1;
}
else if(choice === 3){
document.getElementById("eva").innerHTML = "Draw"
document.getElementById("player").className = scissor_c;
document.getElementById("computer").className = scissor_c;
}
else{
document.getElementById("eva").innerHTML = "ERROR"
}
document.getElementById("p_score").innerHTML = p_count;
document.getElementById("c_score").innerHTML = c_count;
}
// Funtion to reset the values of the program
function reset(){
console.log("GAME HAS BEEN RESTARTED");
p_count=0;
c_count=0;
document.getElementById("p_score").innerHTML = p_count;
document.getElementById("c_score").innerHTML = c_count;
document.getElementById("player").className = "";
document.getElementById("computer").className = "";
}className