-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
94 lines (77 loc) · 3.75 KB
/
Copy pathscript.js
File metadata and controls
94 lines (77 loc) · 3.75 KB
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
let options = ["ROCK", "PAPER", "SCISSORS"];
let playerScore = 0;
let computerScore = 0;
function computerSelection() {
let randomNum = Math.floor(Math.random() * 3);
return options[randomNum];
};
function playRound(playerSelection, computerSelection) {
if(playerScore == 5 || computerScore == 5) {
if(playerScore == 5) {
roundResult.textContent = "You have won against the computer, just wow :)";
}
else {
roundResult.textContent = "You have lost to the computer, just wow :(";
}
}
else {
if ((playerSelection == "ROCK" && computerSelection == "ROCK") || (playerSelection == "PAPER" && computerSelection == "PAPER") || (playerSelection == "SCISSORS" && computerSelection == "SCISSORS")){
roundResult.textContent = "You draw!";
resultDiv.textContent = "Player Score: " + playerScore + " | " + "Computer Score " + computerScore;
return "You Draw!";
}
else if (playerSelection == "ROCK" && computerSelection == "SCISSORS"){
playerScore++;
roundResult.textContent = "You Win! Rock beats Scissors";
resultDiv.textContent = "Player Score: " + playerScore + " | " + "Computer Score " + computerScore;
return "You Win! Rock beats Scissors";
}
else if (playerSelection == "ROCK" && computerSelection == "PAPER") {
computerScore++;
roundResult.textContent = "You Lose! Paper beats Rock";
resultDiv.textContent = "Player Score: " + playerScore + " | " + "Computer Score " + computerScore;
return "You Lose! Paper beats Rock"
}
else if (playerSelection == "PAPER" && computerSelection == "SCISSORS"){
computerScore++;
roundResult.textContent = "You Lose! Scissors beats Paper";
resultDiv.textContent = "Player Score: " + playerScore + " | " + "Computer Score " + computerScore;
return "You Lose! Scissors beats Paper";
}
else if (playerSelection == "PAPER" && computerSelection == "ROCK") {
playerScore++;
roundResult.textContent = "You Win! Paper beats Rock";
resultDiv.textContent = "Player Score: " + playerScore + " | " + "Computer Score " + computerScore;
return "You Win! Paper beats Rock"
}
else if (playerSelection == "SCISSORS" && computerSelection == "ROCK"){
computerScore++;
roundResult.textContent = "You Lose! Rock beats Scissors";
resultDiv.textContent = "Player Score: " + playerScore + " | " + "Computer Score " + computerScore;
return "You Lose! Rock beats Scissors";
}
else if (playerSelection == "SCISSORS" && computerSelection == "PAPER") {
playerScore++;
roundResult.textContent = "You Win! Scissors beats Paper";
resultDiv.textContent = "Player Score: " + playerScore + " | " + "Computer Score " + computerScore;
return "You Win! Scissors beats Paper";
}
}
}
let rockButton = document.getElementById("rockButton");
let paperButton = document.getElementById("paperButton");
let scissorsButton = document.getElementById("scissorsButton");
rockButton.addEventListener("click",function () {
playRound("ROCK", computerSelection());
});
paperButton.addEventListener("click",function () {
playRound("PAPER", computerSelection());
});
scissorsButton.addEventListener("click",function () {
playRound("SCISSORS", computerSelection());
});
let container = document.getElementById('container');
let roundResult = document.createElement('div');
let resultDiv = document.createElement('div');
container.appendChild(roundResult);
container.appendChild(resultDiv);