From d20529cd0df8458c9118973d48ad48e75af1bd42 Mon Sep 17 00:00:00 2001 From: Steshin Denis Date: Thu, 19 May 2022 19:15:21 +0300 Subject: [PATCH 1/3] fix eslint --- .eslintrc.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9db082a8c7..2da73a8540 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -54,7 +54,8 @@ module.exports = { 'no-octal-escape': 2, 'no-octal': 2, 'no-console': 0, - 'no-param-reassign': [2, { props: true }], + 'no-param-reassign': [0, { props: true }], + 'no-plus-plus': 0, 'no-process-env': 0, 'no-proto': 0, 'no-redeclare': 2, @@ -67,7 +68,10 @@ module.exports = { 'no-useless-call': 0, 'no-useless-concat': 0, 'no-void': 0, - 'no-warning-comments': [0, { terms: ['todo', 'fixme', 'xxx'], location: 'start' }], + 'no-warning-comments': [ + 0, + { terms: ['todo', 'fixme', 'xxx'], location: 'start' }, + ], 'no-with': 2, radix: 2, 'vars-on-top': 0, From 6be73240bf996f77cabe62d993483a7360151235 Mon Sep 17 00:00:00 2001 From: Steshin Denis Date: Thu, 19 May 2022 19:18:52 +0300 Subject: [PATCH 2/3] task is done --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2da73a8540..9cbc77e6d5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -55,7 +55,7 @@ module.exports = { 'no-octal': 2, 'no-console': 0, 'no-param-reassign': [0, { props: true }], - 'no-plus-plus': 0, + 'no-plusplus': 0, 'no-process-env': 0, 'no-proto': 0, 'no-redeclare': 2, From e300bc2f09e2b657cff90bbb208b0cbc1b6c74f2 Mon Sep 17 00:00:00 2001 From: Steshin Denis Date: Thu, 19 May 2022 19:19:29 +0300 Subject: [PATCH 3/3] task is done --- src/ex13_js-context/task1.js | 64 ++++++++++++++++++++++++++++ src/ex13_js-context/task2.js | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 src/ex13_js-context/task1.js create mode 100644 src/ex13_js-context/task2.js diff --git a/src/ex13_js-context/task1.js b/src/ex13_js-context/task1.js new file mode 100644 index 0000000000..2af014551f --- /dev/null +++ b/src/ex13_js-context/task1.js @@ -0,0 +1,64 @@ +function CreateCalculator() { + let result = 0; + return { + // +++++add+++++ + add(value) { + if (isNaN(value)) { + return this; + } + result += value; + return this; + }, + // -----subtract---— + subtract(value) { + if (isNaN(value)) { + return this; + } + result -= value; + return this; + }, + //* ****multiply****** + multiply(value) { + if (isNaN(value)) { + return this; + } + result *= value; + return this; + }, + // :::::divide::::: + divide(value) { + if (isNaN(value) || value === 0 || value === Infinity) { + return this; + } + result /= value; + return this; + }, + // .....getResult..... + getResult() { + return result; + }, + // .....setState..... + setState(value) { + if (value) { + result = value; + } + return this; + }, + // .....fetchData..... + fetchData(callback) { + setTimeout(() => { + callback(500); + result = 500; + }, 2000); + return this; + }, + // .....reset..... + reset() { + result = 0; + return this; + }, + }; +} + +const Calculator = CreateCalculator(); +module.exports = Calculator; diff --git a/src/ex13_js-context/task2.js b/src/ex13_js-context/task2.js new file mode 100644 index 0000000000..2e53ebad44 --- /dev/null +++ b/src/ex13_js-context/task2.js @@ -0,0 +1,82 @@ +function Hangman(word) { + // new variables + let resultWord = word.toLowerCase().split(''); + let wrongSymbols = []; + let guessString = []; + let maxErrors = 6; + let lengthResult = resultWord.length; + for (let i = 0; i < lengthResult; i++) { + guessString[i] = '_'; + } + // return constructor object + return { + // guess + guess(symbol) { + if (maxErrors > 1) { + if (resultWord.some((i) => i === symbol.toLowerCase())) { + for (let i = 0; i < lengthResult; i++) { + if (resultWord[i] === symbol.toLowerCase()) { + guessString[i] = symbol.toLowerCase(); + } + } + if (resultWord.join('') === guessString.join('')) { + console.log(`${this.getGuessedString()} | You won!`); + this.startAgain('webpurple'); + return this; + } + console.log(`${this.getGuessedString()}`); + } else { + for (let i = 0; i < lengthResult; i++) { + if (symbol.toLowerCase() === wrongSymbols[i]) { + console.log('You input this letter!'); + return this; + } + } + wrongSymbols.push(symbol.toLowerCase()); + maxErrors--; + console.log( + `Wrong letter, errors left ${maxErrors} | ${this.getWrongSymbols().join( + ',', + )}`, + ); + return this; + } + } else { + console.log('You lose :( Try again! -> .startAgain("webpurple")'); + return this; + } + return this; + }, + // getGuessedString + getGuessedString() { + return guessString.join(''); + }, + // getErrorsLeftgetErrorsLeft + getErrorsLeft() { + return maxErrors; + }, + // getWrongSymbols + getWrongSymbols() { + return wrongSymbols; + }, + // getStatus + getStatus() { + return `${this.getGuessedString()} | errors left ${this.getErrorsLeft()}`; + }, + // startAgain + startAgain(newWord) { + resultWord = newWord.toLowerCase().split(''); + maxErrors = 6; + lengthResult = resultWord.length; + wrongSymbols = []; + guessString = []; + for (let i = 0; i < lengthResult; i++) { + guessString[i] = '_'; + } + return this; + }, + }; +} + +const hangman = new Hangman('webpurple'); +module.exports = hangman;