-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
101 lines (93 loc) · 1.9 KB
/
Copy pathscript.js
File metadata and controls
101 lines (93 loc) · 1.9 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
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
101
let winner;
let result = 0;
for (i=0; i<=5; i++)
{
roundScore = turn();
result = result + roundScore;
}
result > 0 ? console.log('You Win!') : console.log('You Lose!');
function computerPlay()
// Obtains the computers random answer
{
const rand = Math.floor(Math.random() * (3));
switch (rand) {
case 0:
return 'Rock';
case 1:
return 'Scissors';
case 2:
return 'Paper';
default:
break;
}
}
function playerPlay()
//Obtains the answer from the user
{
let playerChoice = prompt('Please enter your choice: Rock, Paper, Or Scissors?').toLowerCase();
switch (playerChoice)
{
case 'rock':
return 'Rock';
case 'scissors':
return 'Scissors';
case 'paper':
return 'Paper';
default:
console.log('i dont think ' + playerChoice + ' was an option, lets try again...');
playerPlay();
}
}
function turn()
{
let computerAnswer = computerPlay();
let playerAnswer = playerPlay();
//Tie Test first
if (playerAnswer == computerAnswer)
{
console.log('Tie!');
return 0;
}
//Player answers rock
if (playerAnswer == 'Rock')
{
if (computerAnswer == 'Paper')
{
console.log('Paper beats Rock, sorry!');
return -1;
}
if (computerAnswer == 'Scissors')
{
console.log('Rock beats Scissors, you win!');
return 1;
}
}
//Player answers Scissors
if (playerAnswer == 'Scissors')
{
if (computerAnswer == 'Rock')
{
console.log('Rock beats Scissors, sorry!');
return -1;
}
if (computerAnswer == 'Paper')
{
console.log('Scissors beats paper , you win!');
return 1;
}
}
//Player answers Paper
if (playerAnswer == 'Paper')
{
if (computerAnswer == 'Scissors')
{
console.log('Scissors beats Paper, sorry!');
return -1;
}
if (computerAnswer == 'Paper')
{
console.log('Scissors beats Paper, you win!');
return 1;
}
}
}