-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
24 lines (21 loc) · 874 Bytes
/
app.js
File metadata and controls
24 lines (21 loc) · 874 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
const hand = ["rock", "paper", "scissors"];
function playRound(humanSelection) {
let computerSelection = hand[Math.floor(Math.random() * hand.length)];
if (
(humanSelection == "rock" && computerSelection == "scissors") ||
(humanSelection == "scissors" && computerSelection == "paper") ||
(humanSelection == "paper" && computerSelection == "rock")
) {
document.querySelector(
"#gameResult"
).innerHTML = `<p>${humanSelection} vs ${computerSelection}</p><h3>The human wins.</h3>`;
} else if (humanSelection == computerSelection) {
document.querySelector(
"#gameResult"
).innerHTML = `<p>${humanSelection} vs ${computerSelection}</p><h3>Tie.</h3>`;
} else {
document.querySelector("#gameResult").innerHTML = `
<p>${humanSelection} vs ${computerSelection}</p><h3>The computer wins.</h3>`;
}
}
//hint: use objects