From 54622bdef7671b180974ed20efdc29d348b5d82a Mon Sep 17 00:00:00 2001 From: Nikolay Date: Wed, 14 Aug 2024 22:57:36 +0500 Subject: [PATCH 1/4] 1st task --- 1-module/1-task/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/1-module/1-task/index.js b/1-module/1-task/index.js index 977f6f3..19f6dd4 100644 --- a/1-module/1-task/index.js +++ b/1-module/1-task/index.js @@ -1,3 +1,14 @@ function factorial(n) { - // ваш код... + if (n < 0) { + return undefined; + } + let result = 1; + let i = 2; + while (i <= n) { + result *=i; + i++; + } + return result; } + +console.log ( factorial(3) ); From 8c5d74410a2aa8f6af1db8a77d19ae422d2c8fd3 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Thu, 15 Aug 2024 21:02:18 +0500 Subject: [PATCH 2/4] 1-module --- 1-module/1-task/index.js | 2 +- 1-module/2-task/index.js | 15 ++++++++++++--- 1-module/3-task/index.js | 4 +++- 1-module/4-task/index.js | 3 ++- 1-module/5-task/index.js | 5 ++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/1-module/1-task/index.js b/1-module/1-task/index.js index 19f6dd4..54b4e02 100644 --- a/1-module/1-task/index.js +++ b/1-module/1-task/index.js @@ -11,4 +11,4 @@ function factorial(n) { return result; } -console.log ( factorial(3) ); +console.log ( factorial (3) ); diff --git a/1-module/2-task/index.js b/1-module/2-task/index.js index e59bf21..7d26fdb 100644 --- a/1-module/2-task/index.js +++ b/1-module/2-task/index.js @@ -10,13 +10,22 @@ function print(text) { * чтобы функция sayHello работала корректно */ function isValid(name) { - // ваш код... -} + if (!name) { + return false; + } + if (name.includes (" ")) { + return false; + } + if (name.length < 4) { + return false; + } + return true; + };// ваш код... function sayHello() { let userName = prompt('Введите ваше имя'); - if (isValid(userName)) { + if (isValid (userName) ) { print(`Welcome back, ${userName}!`); } else { print('Некорректное имя'); diff --git a/1-module/3-task/index.js b/1-module/3-task/index.js index 5c3e6a5..efb1170 100644 --- a/1-module/3-task/index.js +++ b/1-module/3-task/index.js @@ -1,3 +1,5 @@ function ucFirst(str) { - // ваш код... + if (!str) return str; + return str [0].toUpperCase() + str.slice (1);// ваш код... } +alert (ucFirst ("вася")); \ No newline at end of file diff --git a/1-module/4-task/index.js b/1-module/4-task/index.js index 08684b7..df40313 100644 --- a/1-module/4-task/index.js +++ b/1-module/4-task/index.js @@ -1,3 +1,4 @@ function checkSpam(str) { - // ваш код... + const lowerStr = str.toLowerCase(); + return lowerStr.includes ("1xbet") || lowerStr.includes ("xxx") // ваш код... } diff --git a/1-module/5-task/index.js b/1-module/5-task/index.js index b1eda21..357d6d9 100644 --- a/1-module/5-task/index.js +++ b/1-module/5-task/index.js @@ -1,3 +1,6 @@ function truncate(str, maxlength) { - // ваш код... + if (str. length > maxlength) { + return str. slice (0, maxlength -1) + "…";// ваш код... } +return str +} \ No newline at end of file From 45fedadab152162e301e8717697f9c64763404ae Mon Sep 17 00:00:00 2001 From: Nikolay Date: Mon, 19 Aug 2024 20:53:28 +0500 Subject: [PATCH 3/4] 2-module --- 2-module/1-task/index.js | 19 ++++++++++++++++++- 2-module/2-task/index.js | 5 ++++- 2-module/3-task/index.js | 17 ++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/2-module/1-task/index.js b/2-module/1-task/index.js index 5afaa84..77fc19c 100644 --- a/2-module/1-task/index.js +++ b/2-module/1-task/index.js @@ -1,3 +1,20 @@ function sumSalary(salaries) { - // ваш код... + let total = 0; + for (let key in salaries) { + let value = salaries [key]; + if (typeof value === 'number' && isFinite (value) ) { + total +=value; + } + } + return total;// ваш код... } +let salaries = { + John: 1000, + Ann: 1600, + Pete: 1300, + month: 'December', + currency: 'USD', + isPayed: false +} + +console.log (sumSalary (salaries) ); \ No newline at end of file diff --git a/2-module/2-task/index.js b/2-module/2-task/index.js index 7f90874..f63e7b5 100644 --- a/2-module/2-task/index.js +++ b/2-module/2-task/index.js @@ -1,3 +1,6 @@ function isEmpty(obj) { - // ваш код... + for (let key in obj) { + return false; + } + return true // ваш код... } diff --git a/2-module/3-task/index.js b/2-module/3-task/index.js index 7bc6efd..639b4a2 100644 --- a/2-module/3-task/index.js +++ b/2-module/3-task/index.js @@ -1,6 +1,21 @@ let calculator = { - // ваш код +a: 0, +b: 0, +read (a, b) { + this.a = a; + this.b = b; +}, +sum () { + return this.a + this.b; +}, +mul () { + return this.a * this.b; +} }; +calculator.read (3,5); +console.log (calculator.sum () ); +console.log (calculator.mul () ); + // НЕ УДАЛЯТЬ СТРОКУ, НУЖНА ДЛЯ ПРОВЕРКИ window.calculator = calculator; // делает ваш калькулятор доступным глобально From 0c4d81e2a373d17fb45538b1bd7eb9826c5f34b7 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Mon, 19 Aug 2024 21:01:06 +0500 Subject: [PATCH 4/4] 2-module --- 1-module/1-task/index.js | 2 -- 1-module/3-task/index.js | 1 - 2-module/1-task/index.js | 10 ---------- 2-module/3-task/index.js | 4 ---- 4 files changed, 17 deletions(-) diff --git a/1-module/1-task/index.js b/1-module/1-task/index.js index 54b4e02..e165fd0 100644 --- a/1-module/1-task/index.js +++ b/1-module/1-task/index.js @@ -10,5 +10,3 @@ function factorial(n) { } return result; } - -console.log ( factorial (3) ); diff --git a/1-module/3-task/index.js b/1-module/3-task/index.js index efb1170..066ed8e 100644 --- a/1-module/3-task/index.js +++ b/1-module/3-task/index.js @@ -2,4 +2,3 @@ function ucFirst(str) { if (!str) return str; return str [0].toUpperCase() + str.slice (1);// ваш код... } -alert (ucFirst ("вася")); \ No newline at end of file diff --git a/2-module/1-task/index.js b/2-module/1-task/index.js index 77fc19c..7a75b10 100644 --- a/2-module/1-task/index.js +++ b/2-module/1-task/index.js @@ -8,13 +8,3 @@ function sumSalary(salaries) { } return total;// ваш код... } -let salaries = { - John: 1000, - Ann: 1600, - Pete: 1300, - month: 'December', - currency: 'USD', - isPayed: false -} - -console.log (sumSalary (salaries) ); \ No newline at end of file diff --git a/2-module/3-task/index.js b/2-module/3-task/index.js index 639b4a2..1a9e631 100644 --- a/2-module/3-task/index.js +++ b/2-module/3-task/index.js @@ -13,9 +13,5 @@ mul () { } }; -calculator.read (3,5); -console.log (calculator.sum () ); -console.log (calculator.mul () ); - // НЕ УДАЛЯТЬ СТРОКУ, НУЖНА ДЛЯ ПРОВЕРКИ window.calculator = calculator; // делает ваш калькулятор доступным глобально