From 67af420b4741c69ce9b0b935d9c10436fd97816f Mon Sep 17 00:00:00 2001 From: Aristiel Date: Sat, 28 Aug 2021 16:17:16 +0800 Subject: [PATCH] word game --- script.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index bbe8a29..0649f58 100644 --- a/script.js +++ b/script.js @@ -1,4 +1,48 @@ +var PassingMark = function () { + var randMark = Math.ceil(Math.random() * 3) + 1; + return randMark; +}; +var Points = 0; +var WinCounter = PassingMark(); +var WinCounter02 = WinCounter; var main = function (input) { - var myOutputValue = 'hello world'; + var ComputerWords = "a"; + console.log(ComputerWords); + var myOutputValue = "Please continue guessing."; + if (ComputerWords == input && WinCounter == 1) { + return `Congratulations you guessed it right ${WinCounter02} times! The game will end.`; + } + if (ComputerWords != input) { + WinCounter = WinCounter + Points; + Points = 0; + myOutputValue = "Sorry! You're back to square one. Please try again."; + } + if (ComputerWords == input) { + WinCounter = WinCounter - 1; + Points = Points + 1; + myOutputValue = "Congratulations you guessed it right!"; + } + console.log(`WinCounter ${WinCounter}.`); + console.log(`Points ${Points}`); return myOutputValue; }; +//If the computer != players input & the score equals to one, player loses 1 point. +//Three secret words: banana, chisel and faucet. +//Player must guess correctly twice in total. +//Use dice roll to determine the computer choice. +var RollDice = function () { + var randNumber = Math.ceil(Math.random() * 3); + return randNumber; +}; +var WordChoice = function () { + var Computerchoice = RollDice(); + if (Computerchoice == 1) { + return "banana"; + } + if (Computerchoice == 2) { + return "chisel"; + } + if (Computerchoice == 3) { + return "faucet"; + } +};