From ea3f9c398a11b049abbd06bf0054379049456557 Mon Sep 17 00:00:00 2001 From: YusofGotboudine Date: Fri, 20 Mar 2020 14:01:06 +0800 Subject: [PATCH] Yusof Flips Table --- looooooooop.js | 33 ++++++++++++++++++++++++++++++ script.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 looooooooop.js diff --git a/looooooooop.js b/looooooooop.js new file mode 100644 index 0000000..7634289 --- /dev/null +++ b/looooooooop.js @@ -0,0 +1,33 @@ +// var arrayToSearch = [1,2,3,4,5,6,]; +// var toFind = 6; + +// function search (array, data) { +// for (var i = 0; i return true array[i] == data + // Condition 2: End of array && element doesn't match data => return false + } +} + +var answer = search(arrayToSearch, toFind); +answer + +console.log(arrayToSearch[arrayToSearch.length - 1]) \ No newline at end of file diff --git a/script.js b/script.js index 3df1217..8e70da8 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,55 @@ console.log("hello script js"); -var inputHappened = function(currentInput){ - console.log( currentInput ); - return "WOW SOMETHING HAPPEND"; +var attempt = 0; +var totalSecretFound = 0; +var result = false; +var secret = ['c', 'a', 't']; + +function search(array, data, nAttempt, nMatch, aResult) { + for (var i = 0; i < array.length; i++) { + var response; + if (array[i] === data) { + nAttempt++; + nMatch++; + response = "Letter uncovered: " + array[i].toString() + " . Attempts Taken: " + nAttempt.toString(); + console.log(response); + return true; + } else if (i === array.length - 1 && array[i] !== data) { + nAttempt++; + response = "No letter uncovered. " + "Attempts Taken: " + nAttempt.toString(); + console.log(response); + return false; + } + + // Condition 1: Element matches data => return true array[i] == data + // Condition 2: End of array && element doesn't match data => return false + }; }; + +var inputHappened = function (currentInput) { + console.log(currentInput); + + // var hangmanString = '(╯ರ ~ ರ)╯︵ ┻━┻'; + // var hangmanArray = hangmanString.split(''); + + var letterToSearch = currentInput.toString(); + + var wordFound = false; + + var check = search(secret, letterToSearch, attempt, totalSecretFound); + if (check == true) { + totalSecretFound++; + attempt++; + console.log(totalSecretFound); + console.log(attempt); + } else { + attempt++; + console.log(totalSecretFound); + console.log(attempt); + } + +}; + + +//return "WOW SOMETHING HAPPEND"; +;