-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRock_Paper_Scissors.js
39 lines (33 loc) · 1.09 KB
/
Rock_Paper_Scissors.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
// Rock Paper Scissors
// Let's play! You have to return which player won! In case of a draw return Draw!.
// Examples(Input1, Input2 --> Output):
// "scissors", "paper" --> "Player 1 won!"
// "scissors", "rock" --> "Player 2 won!"
// "paper", "paper" --> "Draw!"
dịch: oẳn tù tì
Hãy chơi! Bạn phải trả lại người chơi nào đã thắng! Trong trường hợp hòa trở lại Draw!.
Ví dụ (Đầu vào1, Đầu vào2 -> Đầu ra):
"scissors", "paper" --> "Player 1 won!"
"scissors", "rock" --> "Player 2 won!"
"paper", "paper" --> "Draw!"
code:
//
const rps = (p1, p2) => {
};
//
const rps = (p1, p2) => {
if (p1 === p2) {
return "Draw!";
} else if (
(p1 === "rock" && p2 === "scissors") ||
(p1 === "scissors" && p2 === "paper") ||
(p1 === "paper" && p2 === "rock")
) {
return "Player 1 won!";
} else {
return "Player 2 won!";
}
};
console.log(rps("scissors", "paper")); // Output: "Player 1 won!"
console.log(rps("scissors", "rock")); // Output: "Player 2 won!"
console.log(rps("paper", "paper")); // Output: "Draw!"