forked from rocketacademy/basics-scissors-paper-stone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
84 lines (68 loc) · 1.89 KB
/
script.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
var main = function (input) {
var myOutputValue = 'hello world';
return myOutputValue;
};
// set global var//
var win = 0;
var lose = 0;
var draw = 0;
var troll = 0;
// hack function//
var Hack = function (input) {
if (input == 'Reverse') {
troll += 1;
return 'troll activated';
}
};
// unhack function//
var Hack = function (input) {
if (input == 'Unhack') {
troll -= 1;
return 'troll deactivated';
}
};
// normal function//
var normal = function (input) {
const Play = ['Scissors', 'Paper', 'Stone'];
const random = Math.floor(Math.random() * Play.length);
console.log(random, Play[random]);
if (input == Play[random]) {
draw += 1;
return 'draw: ' + draw;
}
if (input == 'Scissors' && Play[random] == 'Paper' || input == 'Paper' && Play[random] == 'Stone' || input == 'Stone' && Play[random] == 'Scissors') {
win += 1;
return 'Win: ' + win;
}
if (input == 'Paper' && Play[random] == 'Scissors' || input == 'Stone' && Play[random] == 'Paper' || input == 'Scissors' && Play[random] == 'Stone') {
lose += 1;
return 'lose: ' + lose;
}
return 'Error, try again';
};
// reverse function//
var Fake = function (input) {
const Play = ['Scissors', 'Paper', 'Stone'];
const random = Math.floor(Math.random() * Play.length);
console.log(random, Play[random]);
if (input == Play[random]) {
draw += 1;
return 'draw: ' + draw;
}
if (input == 'Scissors' && Play[random] == 'Paper' || input == 'Paper' && Play[random] == 'Stone' || input == 'Stone' && Play[random] == 'Scissors') {
lose += 1;
return 'lose: ' + lose;
}
if (input == 'Paper' && Play[random] == 'Scissors' || input == 'Stone' && Play[random] == 'Paper' || input == 'Scissors' && Play[random] == 'Stone') {
win += 1;
return 'win: ' + win;
}
return 'Error, try again';
};
// calling functions
if (troll == 0) {
normal();
}
if (troll == 1) {
Fake();
}