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
68 lines (53 loc) · 1.5 KB
/
script.js
File metadata and controls
68 lines (53 loc) · 1.5 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
var randomWinsNeeded = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal) + 2;
return randomInteger;
};
var winsNeeded = randomWinsNeeded();
console.log("correct guesses to win=====", winsNeeded);
var randomWordGenerate = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal) + 1;
var randomWord = 0;
if (randomInteger == 1) {
randomWord = "banana";
}
if (randomInteger == 2) {
randomWord = "chisel";
}
if (randomInteger == 3) {
randomWord = "faucet";
}
return randomWord;
};
var winCount = 0;
var main = function (input) {
//var secretWord = randomWordGenerate();
var secretWord = "banana";
var myOutputValue = `You need ${winsNeeded} correct guesses in a row to win`;
console.log("secret word ===", secretWord);
if (input != secretWord) {
winCount = 0;
}
if (input == secretWord) {
winCount += 1;
console.log("curren correct guesses", winCount);
myOutputValue = `You have ${winCount} correct guesses. You need need ${
winsNeeded - winCount
} more correct guesses in a row to win`;
}
if (winCount == winsNeeded) {
myOutputValue = `You guess correctly ${winsNeeded} time. You win!`;
winCount = 0;
winsNeeded = randomWinsNeeded();
console.log("correct guesses to win in new round=====", winsNeeded);
}
return (
"You guessed " +
input +
". The secret word was " +
secretWord +
". " +
myOutputValue
);
};