-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (20 loc) · 921 Bytes
/
script.js
File metadata and controls
28 lines (20 loc) · 921 Bytes
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
function playGame(playerChoice) {
const choices = ['rock', 'paper', 'scissors'];
const computerChoice = choices[Math.floor(Math.random() * choices.length)];
document.getElementById('player-choice').textContent = `Your Choice: ${playerChoice}`;
document.getElementById('computer-choice').textContent = `Computer's Choice: ${computerChoice}`;
const result = determineWinner(playerChoice, computerChoice);
document.getElementById('game-result').textContent = result;
}
function determineWinner(playerChoice, computerChoice) {
if (playerChoice === computerChoice) {
return "It's a tie!";
}
if (
(playerChoice === 'rock' && computerChoice === 'scissors') ||
(playerChoice === 'paper' && computerChoice === 'rock') ||
(playerChoice === 'scissors' && computerChoice ==='paper'))
{
return 'You Win!';
}
return 'Computer Wins!';}