From d6c22e3f17dd49c343a608aeec10530ba146064d Mon Sep 17 00:00:00 2001 From: Aaron Smith Date: Tue, 20 Jun 2023 15:27:03 -0700 Subject: [PATCH] HIDING WORD FROM HINT --- js/functionality.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/functionality.js b/js/functionality.js index 63e61bd..3ee740b 100644 --- a/js/functionality.js +++ b/js/functionality.js @@ -37,6 +37,18 @@ function startGame() { wordDef = JSON.stringify(words[randomNum]).split(":"); wordPrep = wordDef[0].substring(2, wordDef[0].length - 1).trim().replaceAll(" ", "-").replaceAll("'", ""); definitionPrep = wordDef[1].substring(1, wordDef[1].length - 2).replaceAll("'", ""); + const wordLower = wordPrep.toLowerCase(); + /*HIDING WORD FROM HINT*/ + function capitalizeFirstLetter(str) { + return str[0].toUpperCase() + str.slice(1); + } + while (definitionPrep.indexOf(wordLower) !== -1) { + definitionPrep = definitionPrep.replace(wordLower, "~~~~~~"); + } + while (definitionPrep.indexOf(capitalizeFirstLetter(wordLower)) !== -1) { + definitionPrep = definitionPrep.replace(capitalizeFirstLetter(wordLower), "~~~~~~"); + } + /*END HIDING WORD FROM HINT*/ for (let i = 0; i < wordPrep.length; i++) {/*remeber to check for spaces*/ let addThis = " ~ ";