From 0027a78918df1530c26596497485b8132471a036 Mon Sep 17 00:00:00 2001 From: Shania Date: Sat, 28 Aug 2021 13:54:03 +0700 Subject: [PATCH] add base secret word --- script.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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); };