-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14-rps.js
31 lines (26 loc) · 845 Bytes
/
14-rps.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
// WPU Coding Challenge 2024 by Peter Shaan
// 14/365
// https://www.codewars.com/kata/5672a98bdbdd995fad00000f/train/javascript
// const rps = (p1, p2) => {
// if (p1 === p2) return 'Draw!'
// if (p1 === 'rock' && p2 === 'scissors' || p1 === 'scissors' && p2 === 'paper' || p1 === 'paper' && p2 === 'rock') {
// return 'Player 1 won!'
// } else {
// return 'Player 2 won!'
// }
// };
const rps = (p1, p2) => {
const rules = {
rock: 'scissors',
paper: 'rock',
scissors: 'paper'
}
// if (p1 === p2) {
// return 'Draw!'
// } else {
// // return `${rules[p1]}`
// return `Player ${(rules[p1] === p2) ? '1' : '2'} won!`
// }
return p1 === p2 ? 'Draw!' : `Player ${(rules[p1] === p2) ? '1' : '2'} won!`
}
console.log(rps('rock', 'scissors'))