forked from rocketacademy/basics-scissors-paper-stone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (64 loc) · 2.38 KB
/
script.js
File metadata and controls
66 lines (64 loc) · 2.38 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
var userWin = 0;
var totalGames = 0;
var computerWin = 0;
var drawRounds = 0;
var previousWin = '';
var winner = '';
var main = function (input) {
// input validation
var myOutputValue = '';
if (input != 'Rock' || input != 'Paper' || input != 'Scissors') {
myOutputValue = 'Input error, please ensure that input is either Rock, Paper or Scissors';
totalGames = totalGames;
}
//Computer win scenarios
var computerRPS = randomRPS();
if ((input == 'Rock' && computerRPS == 'Paper') || (input == 'Paper' && computerRPS == 'Scissors') || (input == 'Scissors' && computerRPS == 'Rock')) {
computerWin = computerWin + 1;
userWin = userWin;
drawRounds = drawRounds;
totalGames = totalGames + 1;
winner = 'computer';
myOutputValue = `You lost. We have played ${totalGames}, in which you won ${userWin} times, computer won ${computerWin} and there were ${drawRounds}`;
}
// Normal - User win scenarios
if ((input == 'Rock' && computerRPS == 'Scissors') || (input == 'Paper' && computerRPS == 'Rock') || (input == 'Scissors' && computerRPS == 'Paper')) {
computerWin = computerWin;
userWin = userWin + 1;
drawRounds = drawRounds;
totalGames = totalGames + 1;
winner = 'user';
myOutputValue = `You won. We have played ${totalGames}, in which you won ${userWin} times, computer won ${computerWin} and there were ${drawRounds}`;
}
// Normal - Draw scenarios
if (input == computerRPS) {
computerWin = computerWin;
userWin = userWin;
drawRounds = drawRounds + 1;
totalGames = totalGames + 1;
myOutputValue = `Its a draw. We have played ${totalGames}, in which you won ${userWin} times, computer won ${computerWin} and there were ${drawRounds}, and the true winner is ${previousWin}`;
if (totalGames == 0) {
myOutputValue = `Its a draw. We have played ${totalGames}, in which you won ${userWin} times, computer won ${computerWin} and there were ${drawRounds}`;
}
}
// Previous round's winner
previousWin = winner;
return myOutputValue;
};
var randomRPS = function () {
var randomDraw = '';
var randomNumber = Math.random() * 3;
var randomInteger = Math.floor(randomNumber);
var randNum = randomInteger + 1;
console.log(randNum);
if (randNum == 1) {
randomDraw = 'Rock';
}
if (randNum == 2) {
randomDraw = 'Paper';
}
if (randNum == 3) {
randomDraw = 'Scissors';
}
return randomDraw;
};