-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
157 lines (156 loc) · 4.27 KB
/
Copy pathapp.js
File metadata and controls
157 lines (156 loc) · 4.27 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
145
146
147
148
149
150
151
152
153
154
155
156
157
var userScore=0;
var computerScore=0;
var c;
const userScore_span=document.getElementById("user-score");
const computerScore_span=document.getElementById("comp-score");
const scorBoard_div=document.querySelector(".score-board");
const result_p=document.querySelector(".result > p");
const one_div=document.getElementById("O");
const two_div=document.getElementById("T");
const three_div=document.getElementById("Th");
const four_div=document.getElementById("F");
const five_div=document.getElementById("Fi");
const six_div=document.getElementById("S");
let bat_b=document.getElementById("bat");
let bowl_b=document.getElementById("bowl");
function getComputerChoice(){
const choices= [1,2,3,4,5,6];
const randomNumber=Math.floor(Math.random() * 6);
return choices[randomNumber];
}
function bat(runs){
userScore+=runs;
console.log("USER SCORES" + userScore + "RUNS");
userScore_span.innerHTML=userScore;
}
function user_out(userChoice,computerChoice){
result_p.innerHTML=`User: ${userChoice} & Comp: ${computerChoice} so USER IS OUT, Please click on Bowl button to Bowl to the COMP `;
userScore=0;
function comp_bat(){
one_div.addEventListener('click', function(){
game_2(1);
})
two_div.addEventListener('click', function(){
game_2(2);
})
three_div.addEventListener('click', function(){
game_2(3);
})
four_div.addEventListener('click', function(){
game_2(4);
})
five_div.addEventListener('click', function(){
game_2(5);
})
six_div.addEventListener('click', function(){
game_2(6);
})
}
comp_bat();
}
function game_1(userChoice){
const computerChoice=getComputerChoice();
result_p.innerHTML=`USER is Batting & COMP is Bowling :`+ ` ` + computerChoice;
console.log("computer:"+computerChoice);
if(userChoice!=computerChoice)
{
bat(userChoice);
}
if(userChoice==computerChoice){
user_out(userChoice,computerChoice);
userScore=0;
}
}
function bowl(runs){
computerScore+=runs;
console.log("COMPUTER SCORES" + computerScore + "RUNS");
computerScore_span.innerHTML=computerScore;
}
function comp_out(userChoice,computerChoice){
result_p.innerHTML=`Comp: ${computerChoice} & User: ${userChoice} so COMP IS OUT, Please click on Bat buttton to Bat against the COMP `;
computerScore=0;
function user_bat(){
one_div.addEventListener('click', function(){
game_1(1);
})
two_div.addEventListener('click', function(){
game_1(2);
})
three_div.addEventListener('click', function(){
game_1(3);
})
four_div.addEventListener('click', function(){
game_1(4);
})
five_div.addEventListener('click', function(){
game_1(5);
})
six_div.addEventListener('click', function(){
game_1(6);
})
}
user_bat();
}
function game_2(userChoice){
const computerChoice=getComputerChoice();
result_p.innerHTML=`USER is Bowling & COMP is Batting :` + ` ` + computerChoice;
console.log("computer:"+computerChoice);
if(computerChoice!=userChoice){
bowl(computerChoice);
}
if(computerChoice==userChoice){
comp_out(userChoice,computerChoice);
computerScore=0;
}
}
function user(){
one_div.addEventListener('click', function(){
game_1(1);
})
two_div.addEventListener('click', function(){
game_1(2);
})
three_div.addEventListener('click', function(){
game_1(3);
})
four_div.addEventListener('click', function(){
game_1(4);
})
five_div.addEventListener('click', function(){
game_1(5);
})
six_div.addEventListener('click', function(){
game_1(6);
})
}
function comp(){
one_div.addEventListener('click', function(){
game_2(1);
})
two_div.addEventListener('click', function(){
game_2(2);
})
three_div.addEventListener('click', function(){
game_2(3);
})
four_div.addEventListener('click', function(){
game_2(4);
})
five_div.addEventListener('click', function(){
game_2(5);
})
six_div.addEventListener('click', function(){
game_2(6);
})
}
user_main=(choice)=>{
c=choice;
if(choice==1)
{
user();
}
if(choice==0)
{
comp();
}
}