-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
123 lines (101 loc) · 3.13 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
let userScore = 0;
let comScore = 0;
const choices = document.querySelectorAll(".choices");
const compGame = (comChoice) => {
const options = ["Rock", "Paper", "Scissors"];
const choiceidx = Math.floor(Math.random * 3);
return options[choiceidx];
}
const draw = () => {
console.log("Game was draw");
}
const showWinner = (userWin) => {
if (userWin){
console.log("You win!")
} else {
console.log("You lose!")
}
};
const userGame = (userChoice) => {
console.log("user choice =", userChoice);
console.log("comp choice=", comChoice);
if (userChoice === comChoice) {
//Draw Game
drawGame();
} else {
let userWin = true;
if (userChoice === "Rock") {
//Scissors, Paper
userWin = compChoice === "paper" ? false: true;
} else if (userChoice=== "Paper") {
//Rock , Scissors
userWin = compChoice === "Rock" ? true : false;
} else {
//rock, paper
userWin = compChoice === "Scissors" ? true: false;
}
}
showWinner(userWin);
}
choices.forEach((choices) => {
console.log(choices);
choices.addEventListener("click", () => {
const choiceId = choices.getAttribute("id");
console.log("choice was clicked", choiceId);
});
});
//Repeat
/* let userScore = 0;
let compScore = 0;
const choices = document.querySelectorAll(".choices");
const msg = document.querySelector("#msg")
const userScores = document.querySelector("#user-score")
const compScores = document.querySelector("#com-score")
const compGame= (comChoice) => {
const options = ["Rock", "Paper", "Scissors"];
const optionIdx = Math.floor(Math.random(options * 3));
return options[optionIdx];
};
const draw = () => {
console.log("The game was draw");
msg.innerHTML= "The game is draw!"
msg.style.backgroundColor= "yellow"
}
const showWinner = (win) => {
if(userWin) {
userScore++;
userScores.innerHTML = userScore
msg.innerHTML="You Win!"
msg.style.backgroundColor = "green"
} else {
compScore++;
compScores.innerHTML = compScore
msg.innerHTML = "You lose!";
msg.style.backgroundColor= "red"
}
}
const userGame = (userchoice) => {
console.log("user choice =", userGame);
console.log("Comp choice =", compGame);
if (userchoice === comChoice) {
draw();
}else {
let userWin = true;
if (userchoice=== "Rock"){
//paper, scissor
userWin = comChoice === "Paper" ? false:true;
}else if (userChoice === "Paper") {
//rock, scissors
userWin= comChoice === "Scissors"?false:true;
} else (
//paper, scissor
userWin= comChoice==="Rock"? false:true);
}
}
choices.forEach((choices) => {
console.log(choices);
choices.addEventListener("click", () => {
const choiceId = choices.getAttribute("id");
console.log("Choice was clicked", choiceId);
});
}); */