From 6c3cc373c2f967e962186ba20ab18bb1fbcefd27 Mon Sep 17 00:00:00 2001 From: kopp3r Date: Mon, 30 Aug 2021 20:25:48 +0800 Subject: [PATCH 1/7] new file for secret word --- script.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index bbe8a29..b040b02 100644 --- a/script.js +++ b/script.js @@ -1,4 +1,38 @@ +var BANANA = "banana"; +var CHISEL = "chisel"; +var FAUCET = "faucet"; +var winCount = 0; + +var guessOptions = function () { + var randomDecimal = Math.random() * 3; + var randomInteger = Math.floor(randomDecimal); + if (randomInteger == 0) { + return "banana"; + } else if (randomInteger == 1) { + return "chisel"; + } else if (randomInteger == 2) { + return "faucet"; + } +}; +var isGuessCorrect = function (guess, guessed) { + if (guess == guessed) { + winCount = winCount + 1; + } +}; + var main = function (input) { - var myOutputValue = 'hello world'; + var word = guessOptions(); + console.log(word); + console.log(input); + isGuessCorrect(input, word); + console.log(winCount); + var myOutputValue = + "The secret word is " + + word + + ". You guessed " + + input + + ".
You need " + + (2 - winCount) + + " more correct guesses to win."; return myOutputValue; }; From d1ec7cddfa14b35c6a7915751c48bbf957c4c12e Mon Sep 17 00:00:00 2001 From: kopp3r Date: Thu, 2 Sep 2021 15:48:01 +0800 Subject: [PATCH 2/7] secret word twice --- script.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index b040b02..ee22cc6 100644 --- a/script.js +++ b/script.js @@ -16,7 +16,10 @@ var guessOptions = function () { }; var isGuessCorrect = function (guess, guessed) { if (guess == guessed) { - winCount = winCount + 1; + winCount += 1; + } + if (guess != guessed) { + winCount = 0; } }; @@ -25,6 +28,9 @@ var main = function (input) { console.log(word); console.log(input); isGuessCorrect(input, word); + if (winCount > 2) { + winCount -= 1; + } console.log(winCount); var myOutputValue = "The secret word is " + From 7ca22201002c20ddaebc4023a07d80bf184cd56a Mon Sep 17 00:00:00 2001 From: kopp3r Date: Thu, 2 Sep 2021 17:33:49 +0800 Subject: [PATCH 3/7] secret word x --- script.js | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index ee22cc6..f28841c 100644 --- a/script.js +++ b/script.js @@ -6,6 +6,7 @@ var winCount = 0; var guessOptions = function () { var randomDecimal = Math.random() * 3; var randomInteger = Math.floor(randomDecimal); + return "banana"; if (randomInteger == 0) { return "banana"; } else if (randomInteger == 1) { @@ -14,6 +15,23 @@ var guessOptions = function () { return "faucet"; } }; + +var correctsToWin = function () { + var randomDecimal = Math.random() * 3; + var randomInteger = Math.floor(randomDecimal); + if (randomInteger == 0) { + return 2; + } else if (randomInteger == 1) { + return 3; + } else if (randomInteger == 2) { + return 4; + } +}; + +var staticCorrectsToWin = 1; + +var resetScore = function () {}; + var isGuessCorrect = function (guess, guessed) { if (guess == guessed) { winCount += 1; @@ -25,20 +43,40 @@ var isGuessCorrect = function (guess, guessed) { var main = function (input) { var word = guessOptions(); + console.log("word"); console.log(word); + console.log("input"); console.log(input); isGuessCorrect(input, word); - if (winCount > 2) { - winCount -= 1; + + if (staticCorrectsToWin == 1) { + staticCorrectsToWin = correctsToWin(); } + + console.log("winCount"); console.log(winCount); + console.log("staticCorrectsToWin"); + console.log(staticCorrectsToWin); + var myOutputValue = "The secret word is " + word + ". You guessed " + input + ".
You need " + - (2 - winCount) + + (staticCorrectsToWin - winCount) + " more correct guesses to win."; + if (winCount == staticCorrectsToWin) { + myOutputValue = + "The secret word is " + + word + + ". You guessed " + + input + + ".
You have guessed " + + staticCorrectsToWin + + " times correctly. You win!"; + staticCorrectsToWin = correctsToWin(); + winCount = 0; + } return myOutputValue; }; From a9259d88f6e0d31472f88d01efdd488a96efe1c6 Mon Sep 17 00:00:00 2001 From: kopp3r Date: Thu, 2 Sep 2021 18:19:20 +0800 Subject: [PATCH 4/7] secret word twice 2 --- script.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index f28841c..a61c757 100644 --- a/script.js +++ b/script.js @@ -6,7 +6,7 @@ var winCount = 0; var guessOptions = function () { var randomDecimal = Math.random() * 3; var randomInteger = Math.floor(randomDecimal); - return "banana"; + if (randomInteger == 0) { return "banana"; } else if (randomInteger == 1) { @@ -16,6 +16,17 @@ var guessOptions = function () { } }; +var prevWord = "whatever"; + +var noRepeatGuessOptions = function () { + word1 = prevWord; + while (word1 == prevWord) { + word1 = guessOptions(); + } + prevWord = word1; + return word1; +}; + var correctsToWin = function () { var randomDecimal = Math.random() * 3; var randomInteger = Math.floor(randomDecimal); @@ -30,8 +41,6 @@ var correctsToWin = function () { var staticCorrectsToWin = 1; -var resetScore = function () {}; - var isGuessCorrect = function (guess, guessed) { if (guess == guessed) { winCount += 1; @@ -42,7 +51,7 @@ var isGuessCorrect = function (guess, guessed) { }; var main = function (input) { - var word = guessOptions(); + var word = noRepeatGuessOptions(); console.log("word"); console.log(word); console.log("input"); From 09ad58d67e12d42eeeebdfc3116a117141c5e7f4 Mon Sep 17 00:00:00 2001 From: kopp3r Date: Fri, 3 Sep 2021 17:23:14 +0800 Subject: [PATCH 5/7] dice within --- script.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index a61c757..e21db0c 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,3 @@ -var BANANA = "banana"; -var CHISEL = "chisel"; -var FAUCET = "faucet"; var winCount = 0; var guessOptions = function () { @@ -50,7 +47,7 @@ var isGuessCorrect = function (guess, guessed) { } }; -var main = function (input) { +var secretWord = function (input) { var word = noRepeatGuessOptions(); console.log("word"); console.log(word); @@ -89,3 +86,61 @@ var main = function (input) { } return myOutputValue; }; + +// start code for dice-within + +var rollDice = function () { + var diceNumber = Math.floor(Math.random() * 6) + 1; + return diceNumber; +}; + +var withinNumber = function () { + var randomDecimal = Math.random() * 3; + var randomInteger = Math.floor(randomDecimal) + 1; + return randomInteger; +}; + +var prevWithinNumber = 0; + +var checkIfWin = function (guess, roll, within) { + if (guess <= roll + within && guess >= roll - within) { + return true; + } + return false; +}; + +var main = function (input) { + var diceRoll = rollDice(); + // No repeat Within number + var inNumber1 = function () { + if (prevWithinNumber == 0) { + return withinNumber(); + } + return prevWithinNumber; + }; + var inNumber = inNumber1(); + var checkWin = checkIfWin(input, diceRoll, inNumber); + console.log("input"); + console.log(input); + console.log("diceRoll"); + console.log(diceRoll); + console.log("inNumber"); + console.log(inNumber); + console.log("checkWin"); + console.log(checkWin); + + var myOutputValue = + "You lost. You guessed " + input + ". You rolled " + diceRoll; + if (checkWin == true) { + myOutputValue = + "You won. You guessed " + + input + + ". You rolled " + + diceRoll + + ". Your guess is within the buffer of " + + inNumber + + "."; + prevWithinNumber = withinNumber(); + } + return myOutputValue; +}; From 4647ecc1fc49a9f111fe89d4b73a4f48a6a4c09b Mon Sep 17 00:00:00 2001 From: kopp3r Date: Fri, 3 Sep 2021 18:18:36 +0800 Subject: [PATCH 6/7] dice within with 2 dice --- script.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/script.js b/script.js index e21db0c..83fdbbf 100644 --- a/script.js +++ b/script.js @@ -110,7 +110,8 @@ var checkIfWin = function (guess, roll, within) { }; var main = function (input) { - var diceRoll = rollDice(); + var diceRoll1 = rollDice(); + var diceRoll2 = rollDice(); // No repeat Within number var inNumber1 = function () { if (prevWithinNumber == 0) { @@ -119,24 +120,34 @@ var main = function (input) { return prevWithinNumber; }; var inNumber = inNumber1(); - var checkWin = checkIfWin(input, diceRoll, inNumber); + var checkWin1 = checkIfWin(input, diceRoll1, inNumber); + var checkWin2 = checkIfWin(input, diceRoll2, inNumber); console.log("input"); console.log(input); console.log("diceRoll"); - console.log(diceRoll); + console.log(diceRoll1); + console.log(diceRoll2); console.log("inNumber"); console.log(inNumber); console.log("checkWin"); - console.log(checkWin); + console.log(checkWin1); + console.log(checkWin2); var myOutputValue = - "You lost. You guessed " + input + ". You rolled " + diceRoll; - if (checkWin == true) { + "You lost. You guessed " + + input + + ". You rolled " + + diceRoll1 + + " and " + + diceRoll2; + if (checkWin1 == true || checkWin2 == true) { myOutputValue = "You won. You guessed " + input + ". You rolled " + - diceRoll + + diceRoll1 + + " and " + + diceRoll2 + ". Your guess is within the buffer of " + inNumber + "."; From c83bb25f46956846ce291379cf466a6d35f00610 Mon Sep 17 00:00:00 2001 From: kopp3r Date: Sat, 4 Sep 2021 14:16:02 +0800 Subject: [PATCH 7/7] add 4D round --- script.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/script.js b/script.js index 83fdbbf..f7e152d 100644 --- a/script.js +++ b/script.js @@ -87,13 +87,20 @@ var secretWord = function (input) { return myOutputValue; }; -// start code for dice-within +// start code for 4D var rollDice = function () { var diceNumber = Math.floor(Math.random() * 6) + 1; return diceNumber; }; +var roll4D = function () { + var fourNumber = Math.floor(Math.random() * 10000); + return fourNumber; +}; + +var start4D = false; + var withinNumber = function () { var randomDecimal = Math.random() * 3; var randomInteger = Math.floor(randomDecimal) + 1; @@ -109,9 +116,13 @@ var checkIfWin = function (guess, roll, within) { return false; }; +var score = 0; + var main = function (input) { var diceRoll1 = rollDice(); var diceRoll2 = rollDice(); + var number4D = roll4D(); + // No repeat Within number var inNumber1 = function () { if (prevWithinNumber == 0) { @@ -132,15 +143,12 @@ var main = function (input) { console.log("checkWin"); console.log(checkWin1); console.log(checkWin2); + console.log("start4D"); + console.log(start4D); - var myOutputValue = - "You lost. You guessed " + - input + - ". You rolled " + - diceRoll1 + - " and " + - diceRoll2; - if (checkWin1 == true || checkWin2 == true) { + var myOutputValue; + if (start4D == false && (checkWin1 == true || checkWin2 == true)) { + console.log("Executed win"); myOutputValue = "You won. You guessed " + input + @@ -152,6 +160,57 @@ var main = function (input) { inNumber + "."; prevWithinNumber = withinNumber(); + if (score < 2) { + score += 1; + if (score > 1) { + start4D = true; + myOutputValue = + "You won. You guessed " + + input + + ". You rolled " + + diceRoll1 + + " and " + + diceRoll2 + + ". Your guess is within the buffer of " + + inNumber + + ". Now you'll enter the 4D round!"; + } + } else if (score == 2) { + score = 1; + } + + console.log("score"); + console.log(score); + } else if (start4D == true && input == number4D) { + start4D = false; + score = 0; + myOutputValue = + "You won. You guessed " + + input + + ". Your 4D roll is " + + number4D + + ". Now you'll return to normal dice round!"; + } else if (start4D == true && input != number4D) { + start4D = false; + score = 0; + myOutputValue = + "You lost. You guessed " + + input + + ". Your 4D roll is " + + number4D + + ". Now you'll return to normal dice round!"; + } else { + score = 0; + console.log("score"); + console.log(score); + myOutputValue = + "You lost. You guessed " + + input + + ". You rolled " + + diceRoll1 + + " and " + + diceRoll2; } + return myOutputValue; };