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
119 lines (107 loc) · 2.88 KB
/
script.js
File metadata and controls
119 lines (107 loc) · 2.88 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var AWAITING_USER_NAME = "awaiting user name";
var PSP_GAME = "psp game";
var currentGameMode = AWAITING_USER_NAME;
var userName = "";
console.log("global");
var winCount = 0;
var loseCount = 0;
var drawCount = 0;
var totalCount = function (winCount, loseCount, drawCount) {
return Number(winCount) + Number(loseCount) + Number(drawCount);
};
console.log("stats");
var winPercentage = function () {
return Math.floor((Number(winCount) * 100) / totalCount);
};
console.log("percent");
var main = function (input) {
var myOutputValue = "";
if ((currentGameMode = AWAITING_USER_NAME)) {
userName = input;
currentGameMode = PSP_GAME;
myOutputValue =
"Welcome to the SPS club, " +
userName +
"!" +
"<br><br>" +
"Please start the game by choosing either scissors, paper or stone.";
console.log(main);
} else if ((currentGameMode = PSP_GAME)) {
var gamePlay = "";
var lowercaseInput = input.toLowerCase();
var gameNumber = generateRandomNumber();
if (gameNumber == 1) {
gamePlay = "scissors";
}
if (gameNumber == 2) {
gamePlay = "paper";
}
if (gameNumber == 3) {
gamePlay = "stone";
}
var myOutputValue =
"Tough luck," +
userName +
"<br> You lost! You played: " +
input +
", the computer played: " +
gamePlay +
"<br> Try again! <br> Wins:" +
Number(winCount) +
" <br> Losses: " +
Number(loseCount) +
"Winninig percentage: " +
winPercentage;
}
if (
(gamePlay == "scissors" && lowercaseInput == "stone") ||
(gamePlay == "stone" && lowercaseInput == "paper") ||
(gamePlay == "paper" && lowercaseInput == "scissors")
) {
myOutputValue =
"Wow!" +
userName +
" <br> You won! You played: " +
input +
", the computer played: " +
gamePlay +
" <br> Well done! Please enter 'secret' to activate the new game mode! <br> Wins:" +
Number(winCount) +
" <br> Losses: " +
Number(loseCount) +
"Winninig percentage: " +
winPercentage;
}
if (lowercaseInput == gamePlay) {
myOutputValue =
"What are the odds?" +
userName +
"<br> It's a draw! You played: " +
input +
", the computer played: " +
gamePlay +
"<br> Try a little harder! <br> Wins:" +
Number(winCount) +
" <br> Losses: " +
Number(loseCount) +
"Winninig percentage: " +
winPercentage;
}
if (
!(
lowercaseInput === "scissors" ||
lowercaseInput === "paper" ||
lowercaseInput === "stone"
)
) {
myOutputValue =
"to start the game, please only input scissors, paper or stone.";
}
return myOutputValue;
};
var generateRandomNumber = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
var randomNumber = randomInteger + 1;
return randomNumber;
};