-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockpaper.js
52 lines (44 loc) · 1.49 KB
/
rockpaper.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
// it is made by Ajkouva
// Date: 27th December 2024
let Score ={
wins: 0,
losses: 0,
draw: 0
};
function updateScore(){
document.querySelector('.js-score').innerHTML = `Player Win = ${Score.wins} | Computer Win = ${Score.losses} | Draws = ${Score.draw}`
};
function result(playerChoice) {
const computerChoice = computerMove();
let gameResult ='';
let cssresult = document.querySelector('.css-result');
if (playerChoice === computerChoice) {
gameResult = 'Draw';
cssresult.style.backgroundColor = 'gray';
} else if (playerChoice === 'rock' && computerChoice === 'scissors' || playerChoice === 'paper' && computerChoice === 'rock' || playerChoice === 'scissors' && computerChoice === 'paper') {
gameResult = 'You win';
cssresult.style.backgroundColor = 'green';
} else {
gameResult = 'You lose';
cssresult.style.backgroundColor = 'red';
}
if (gameResult === 'You win') {
Score.wins++;
} else if (gameResult === 'You lose') {
Score.losses++;
} else if (gameResult === 'Draw') {
Score.draw++;
}
updateScore();
document.querySelector('.js-result').innerHTML = `You pick ${playerChoice} | Computer pick ${computerChoice} | ${gameResult}`
};
function computerMove() {
const randomNumber = Math.random();
if (randomNumber < 0.34) {
return 'rock';
} else if (randomNumber <= 0.67) {
return 'paper';
} else {
return 'scissors';
}
};