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
43 lines (38 loc) · 1.33 KB
/
script.js
File metadata and controls
43 lines (38 loc) · 1.33 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
var CorrectGuessCounter = 0;
var CorrectGuessToWin = 2;
var main = function (input) {
var SecretWord = chooseSecretWord();
console.log("selecting SecretWord");
console.log(SecretWord);
var myOutputValue =
"You selected '" +
input +
"' which is not the secret word. Please try again.";
//note that the sequence of the if functions matter as it determines the statement first
if (input == SecretWord && CorrectGuessCounter == 1) {
CorrectGuessCounter = CorrectGuessCounter + 1;
var CorrectGuessRemainingToWin = CorrectGuessToWin - CorrectGuessCounter;
console.log("counting correct guesses");
console.log(CorrectGuessCounter);
return `You guessed correctly twice. You win.`;
}
if (input == SecretWord) {
CorrectGuessCounter = CorrectGuessCounter + 1;
var CorrectGuessRemainingToWin = CorrectGuessToWin - CorrectGuessCounter;
console.log("counting correct guesses");
console.log(CorrectGuessCounter);
return `You guessed correctly. You need ${CorrectGuessRemainingToWin} more correct guess to win.`;
}
return myOutputValue;
};
var chooseSecretWord = function () {
var randomDecimal = Math.random() * 3;
var randomSecretWord = Math.floor(randomDecimal);
if (randomSecretWord == 0) {
return "banana";
}
if (randomSecretWord == 1) {
return "chisel";
}
return "faucet";
};