diff --git a/script.js b/script.js index bbe8a29..933d77b 100644 --- a/script.js +++ b/script.js @@ -1,4 +1,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}.

You have guessed ${correct} secret word(s) correctly.`; +}; + var main = function (input) { - var myOutputValue = 'hello world'; - return myOutputValue; + 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!" + "

" + message(input, computer, correctGuess); + } + + return message(input, computer, correctGuess); };