-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpsnew.js
More file actions
74 lines (61 loc) · 1.88 KB
/
rpsnew.js
File metadata and controls
74 lines (61 loc) · 1.88 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
// var player1score = 0;
// var player2score = 0;
// while (player1score < 5 || player2score < 5) {
// var playGame = function ()
var hands = ["rock", "paper", "scissors"];
var getHand = function() {
return hands[parseInt(Math.random()*10)%3];
}
var player1 = {
name: "Jude",
hand: getHand()
}
var player2 = {
name: "Lee",
hand: getHand()
}
var playRound = function(player1, player2){
player1.hand();
player2.hand();
if (player1.hand === player2.hand){
console.log("It's a tie - no winner");
} else if ((player1.hand == 0 && player2.hand == 2) ||
(player1.hand == 1 && player2.hand == 0) ||
(player1.hand == 2 && player2.hand == 1)) {
player1score = player1score +1;
console.log( player1.name + " wins");
} else {
player2score = player2score +1;
console.log( player2.name + " wins");
}
}
// }
// // We need to separate these into 2 functions
// if (p1Choice === p2Choice){
// console.log("You tied play again!");
// return nil;
// } else if p1Choice === 0 && p2Choice === 1){
// console.log("Paper covers rock! " + player2.name + " wins");
// return player2;
// } else if p1Choice === 0 && p2Choice === 2){
// console.log("Rock smashes scissors! " + player1.name + " wins");
// return player1;
// } else if p1Choice === 1 && p2Choice === 0){
// console.log("Paper covers rock! " + player1.name + " wins");
// return player1;
// } else if p1Choice === 1 && p2Choice === 2){
// console.log("Scissors cuts paper! " + player2.name + " wins");
// return player2;
// } else if p1Choice === 2 && p2Choice === 0){
// console.log("Rock smashes scissors! " + player2.name + " wins");
// return player2;
// } else if p1Choice === 2 && p2Choice === 1){
// console.log("Scissors cuts paper! " + player1.name + " wins");
// return player1;
// }
// }
// console.log(playRound(player1, player2));