-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game 2 - Rock Paper Scissors.js
100 lines (86 loc) · 1.61 KB
/
Game 2 - 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
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
95
96
97
98
99
100
var input = function()
{
var userChoice = prompt("Do you choose rock, paper or scissors? Type your choice in lower case:");
return userChoice;
};
var compute = function()
{
var computerChoice = Math.random();
if (computerChoice < 0.34)
{
computerChoice = "rock";
}
else if (computerChoice <= 0.67)
{
computerChoice = "paper";
}
else
{
computerChoice = "scissors";
}
return computerChoice;
};
var compare = function (choice1, choice2)
{
console.log ("Computer Choice: " + choice2 + "\n");
console.log ("User Choice: " + choice1 + "\n");
var result = "";
if (choice1 === choice2)
{
result = "It's a tie. Try Again!!!";
console.log(result);
return result;
}
else if (choice1 === "rock")
{
if (choice2 === "scissors")
{
result = "Rock wins!";
console.log(result);
return result;
}
else
{
result = "Paper wins!";
console.log(result);
return result;
}
}
else if (choice1 === "paper")
{
if (choice2 === "rock")
{
result = "Paper wins!";
console.log(result);
return result;
}
else
{
result = "Scissors wins!";
console.log(result);
return result;
}
}
else if (choice1 === "scissors")
{
if (choice2 === "rock")
{
result = "Rock wins!";
console.log(result);
return result;
}
else
{
result = "Scissors wins!";
console.log(result);
return result;
}
}
else
{
result = "Invalid User Choice!";
console.log(result);
return result;
}
};
compare (input(), compute());