forked from rocketacademy/basics-github-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
216 lines (192 loc) · 4.74 KB
/
script.js
File metadata and controls
216 lines (192 loc) · 4.74 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
var winCount = 0;
var guessOptions = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
if (randomInteger == 0) {
return "banana";
} else if (randomInteger == 1) {
return "chisel";
} else if (randomInteger == 2) {
return "faucet";
}
};
var prevWord = "whatever";
var noRepeatGuessOptions = function () {
word1 = prevWord;
while (word1 == prevWord) {
word1 = guessOptions();
}
prevWord = word1;
return word1;
};
var correctsToWin = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
if (randomInteger == 0) {
return 2;
} else if (randomInteger == 1) {
return 3;
} else if (randomInteger == 2) {
return 4;
}
};
var staticCorrectsToWin = 1;
var isGuessCorrect = function (guess, guessed) {
if (guess == guessed) {
winCount += 1;
}
if (guess != guessed) {
winCount = 0;
}
};
var secretWord = function (input) {
var word = noRepeatGuessOptions();
console.log("word");
console.log(word);
console.log("input");
console.log(input);
isGuessCorrect(input, word);
if (staticCorrectsToWin == 1) {
staticCorrectsToWin = correctsToWin();
}
console.log("winCount");
console.log(winCount);
console.log("staticCorrectsToWin");
console.log(staticCorrectsToWin);
var myOutputValue =
"The secret word is " +
word +
". You guessed " +
input +
".<br> You need " +
(staticCorrectsToWin - winCount) +
" more correct guesses to win.";
if (winCount == staticCorrectsToWin) {
myOutputValue =
"The secret word is " +
word +
". You guessed " +
input +
".<br> You have guessed " +
staticCorrectsToWin +
" times correctly. You win!";
staticCorrectsToWin = correctsToWin();
winCount = 0;
}
return myOutputValue;
};
// start code for 4D
var rollDice = function () {
var diceNumber = Math.floor(Math.random() * 6) + 1;
return diceNumber;
};
var roll4D = function () {
var fourNumber = Math.floor(Math.random() * 10000);
return fourNumber;
};
var start4D = false;
var withinNumber = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal) + 1;
return randomInteger;
};
var prevWithinNumber = 0;
var checkIfWin = function (guess, roll, within) {
if (guess <= roll + within && guess >= roll - within) {
return true;
}
return false;
};
var score = 0;
var main = function (input) {
var diceRoll1 = rollDice();
var diceRoll2 = rollDice();
var number4D = roll4D();
// No repeat Within number
var inNumber1 = function () {
if (prevWithinNumber == 0) {
return withinNumber();
}
return prevWithinNumber;
};
var inNumber = inNumber1();
var checkWin1 = checkIfWin(input, diceRoll1, inNumber);
var checkWin2 = checkIfWin(input, diceRoll2, inNumber);
console.log("input");
console.log(input);
console.log("diceRoll");
console.log(diceRoll1);
console.log(diceRoll2);
console.log("inNumber");
console.log(inNumber);
console.log("checkWin");
console.log(checkWin1);
console.log(checkWin2);
console.log("start4D");
console.log(start4D);
var myOutputValue;
if (start4D == false && (checkWin1 == true || checkWin2 == true)) {
console.log("Executed win");
myOutputValue =
"You won. You guessed " +
input +
". You rolled " +
diceRoll1 +
" and " +
diceRoll2 +
". Your guess is within the buffer of " +
inNumber +
".";
prevWithinNumber = withinNumber();
if (score < 2) {
score += 1;
if (score > 1) {
start4D = true;
myOutputValue =
"You won. You guessed " +
input +
". You rolled " +
diceRoll1 +
" and " +
diceRoll2 +
". Your guess is within the buffer of " +
inNumber +
". Now you'll enter the 4D round!";
}
} else if (score == 2) {
score = 1;
}
console.log("score");
console.log(score);
} else if (start4D == true && input == number4D) {
start4D = false;
score = 0;
myOutputValue =
"You won. You guessed " +
input +
". Your 4D roll is " +
number4D +
". Now you'll return to normal dice round!";
} else if (start4D == true && input != number4D) {
start4D = false;
score = 0;
myOutputValue =
"You lost. You guessed " +
input +
". Your 4D roll is " +
number4D +
". Now you'll return to normal dice round!";
} else {
score = 0;
console.log("score");
console.log(score);
myOutputValue =
"You lost. You guessed " +
input +
". You rolled " +
diceRoll1 +
" and " +
diceRoll2;
}
return myOutputValue;
};