-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
72 lines (54 loc) · 1.85 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
const options = document.querySelectorAll("a");
const user = document.querySelector('.user')
const comp = document.querySelector('.comp')
const status = document.querySelector('.status')
const btn = document.querySelector('button')
const initialText = status.innerText
let userScore = compScore = 0;
const checkOutput = (wordGiven) => {
let value = randomOutput();
if (value === wordGiven) {
// console.log(`Match draw, mine was ${value}.`);
status.innerText = `Match draw, mine was ${value}.`;
} else if (value === "Scissors" && wordGiven === "Stone") {
// console.log(`You win, mine was ${value}.`);
status.innerText = `You win, mine was ${value}.`;
userScore+= 1;
user.innerText = userScore;
} else if (value === "Stone" && wordGiven === "Paper") {
// console.log(`You win, mine was ${value}`);
status.innerText = `You win, mine was ${value}`;
userScore += 1;
user.innerText = userScore;
} else if (value === "Paper" && wordGiven === "Scissors") {
// console.log(`You win, mine was ${value}`);
status.innerText = `You win, mine was ${value}`;
userScore += 1;
user.innerText = userScore;
} else {
// console.log(`I win, mine was ${value}`);
status.innerText = `I win, mine was ${value}`;
compScore += 1;
comp.innerText = compScore;
}
};
const randomOutput = () => {
let random = Math.random();
if (random < 0.3) {
return "Scissors";
} else if (random >= 0.3 && random < 0.6) {
return "Paper";
} else {
return "Stone";
}
};
options.forEach((option) => {
option.addEventListener("click", (event) => {
checkOutput(event.target.innerText);
});
});
btn.addEventListener('click', () =>{
userScore = compScore = 0;
user.innerText = comp.innerText = '0'
status.innerText = initialText;
})