-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (27 loc) · 882 Bytes
/
script.js
File metadata and controls
32 lines (27 loc) · 882 Bytes
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
var correctGuess = 0;
var banana = "banana";
var chisel = "chisel";
var faucet = "faucet";
var randomWords = function () {
var random = Math.ceil(Math.random() * 3);
if (random == 1) return banana;
if (random == 2) return chisel;
if (random == 3) return faucet;
};
var message = function (guess, secret, correct) {
return `The guessed word is ${guess} and the secret word is ${secret}. <br><br> You have guessed ${correct} secret word(s) correctly.`;
};
var main = function (input) {
computer = randomWords();
if (input == "") return "Please enter banana, chisel or faucet";
if (correctGuess == 2) {
correctGuess = 0;
}
if (input == computer) {
correctGuess += 1;
}
if (input == computer && correctGuess == 2) {
return "You win!" + "<br><br>" + message(input, computer, correctGuess);
}
return message(input, computer, correctGuess);
};