-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (35 loc) · 1.25 KB
/
script.js
File metadata and controls
37 lines (35 loc) · 1.25 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
var n = null;
var winCount = 0;
var lostCount = 0;
var drawCount = 0;
var count = 0;
var main = function (input) {
if (n == null) {
n = input;
return 'Hello ' + input;
}
++count;
if ((input == 'scissors') || (input == 'stone') || (input == 'paper')) {
var myOutputValue = getResult(input);
return myOutputValue;
};
return "The input options are scissors, stone or paper. Kindly select from these";
};
var getResult = function (input) {
console.log('you have input ' + input);
var handArray = ['stone', 'paper', 'scissors'];
var randomInteger = Math.floor(Math.random() * 3);
var chosenHand = handArray[randomInteger];
console.log('system has chosen ' + chosenHand);
if (input == chosenHand) {
++drawCount;
return ('System also chose ' + chosenHand + '. Its a Draw. No. of draws = ' + drawCount + '/' + count);
};
if (((input == 'scissors') && (chosenHand == 'paper')) ||
((input == 'paper') && (chosenHand == 'stone')) || ((input == 'stone') && (chosenHand == 'scissors'))) {
++winCount;
return 'System chose ' + chosenHand + '. You won :) No. of Wins = ' + winCount + '/' + count;
};
++lostCount;
return 'System chose ' + chosenHand + '. You lose. Try again :) No. of times lost ' + lostCount + '/' + count;
}