-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
106 lines (98 loc) · 2.84 KB
/
app.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
let userScore = 0;
let computerScore = 0;
const scoreboard_div = document.querySelector(".score-board");
const userlabel_span = document.getElementById("user-label");
const computerlabel_span = document.getElementById("computer-label");
const userScore_span = document.getElementById("user-score");
const computerScore_span = document.getElementById("computer-score");
const result_div = document.querySelector(".result");
const rock_div = document.getElementById("r");
const paper_div = document.getElementById("p");
const scissors_div = document.getElementById("s");
// the functions of game
// win, lost and draw function
function win() {
userScore++;
userScore_span.innerHTML = userScore;
computerScore_span.innerHTML = computerScore;
document.getElementById
}
function lost() {
computerScore++;
userScore_span.innerHTML = userScore;
computerScore_span.innerHTML = computerScore;
}
function draw() {
}
// Win and Loss deiciding factor
function win_loss(userChoice, computer_choice) {
if (userChoice == "r") {
if (computer_choice == "p") {
console.log("Comp Wins!" + computer_choice)
lost();
}
if (computer_choice == "s") {
console.log("User Wins!" + userChoice)
win();
}
if (computer_choice == "r") {
console.log("Draw")
draw();
}
}
if (userChoice == "p") {
if (computer_choice == "r") {
console.log("User Wins!" + userChoice)
win();
}
if (computer_choice == "s") {
console.log("Comp Wins!" + computer_choice)
lost();
}
if (computer_choice == "p") {
console.log("Draw")
draw();
}
}
if (userChoice == "s") {
if (computer_choice == "r") {
console.log("Comp Wins!" + computer_choice)
lost();
}
if (computer_choice == "p") {
console.log("User Wins!" + userChoice)
win();
}
if (computer_choice == "s") {
console.log("Draw")
draw();
}
}
}
// WinLoss function defined above
// Computer Choice function
function comp_choice() {
const choices_array = ["r", "p", "s"];
return (choices_array [Math.floor(Math.random()*3)]);
}
// Defines Game function here
function game(userChoice) {
const comp_input = comp_choice();
console.log("So, you hit the -->" + userChoice);
console.log("Computer hit -->" + comp_input);
win_loss(userChoice, comp_input);
}
// Defined main function here
function main() {
rock_div.addEventListener('click', function() {
game("r");
})
paper_div.addEventListener('click', function() {
game("p");
})
scissors_div.addEventListener('click', function() {
game("s");
})
}
// Main Function running
main();