diff --git a/1-module/1-task/index.js b/1-module/1-task/index.js index 977f6f3..e165fd0 100644 --- a/1-module/1-task/index.js +++ b/1-module/1-task/index.js @@ -1,3 +1,12 @@ function factorial(n) { - // ваш код... + if (n < 0) { + return undefined; + } + let result = 1; + let i = 2; + while (i <= n) { + result *=i; + i++; + } + return result; } 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..066ed8e 100644 --- a/1-module/3-task/index.js +++ b/1-module/3-task/index.js @@ -1,3 +1,4 @@ function ucFirst(str) { - // ваш код... + if (!str) return str; + return str [0].toUpperCase() + str.slice (1);// ваш код... } 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 diff --git a/2-module/1-task/index.js b/2-module/1-task/index.js index 5afaa84..7a75b10 100644 --- a/2-module/1-task/index.js +++ b/2-module/1-task/index.js @@ -1,3 +1,10 @@ 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;// ваш код... } 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..1a9e631 100644 --- a/2-module/3-task/index.js +++ b/2-module/3-task/index.js @@ -1,5 +1,16 @@ 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; +} }; // НЕ УДАЛЯТЬ СТРОКУ, НУЖНА ДЛЯ ПРОВЕРКИ