From 2f3a28511e9b1e9aa74e660427d91b3848995bc8 Mon Sep 17 00:00:00 2001 From: Nikita Khrulev Date: Wed, 13 Nov 2024 21:57:26 +0300 Subject: [PATCH] second task --- index.html | 2 +- js/functions.js | 42 ++++++++++++++++++++++++++++++++++++++++++ js/main.js | 24 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 js/functions.js diff --git a/index.html b/index.html index 9fb6740..cb39098 100644 --- a/index.html +++ b/index.html @@ -233,6 +233,6 @@

Изображение успешно загруже

Не удалось загрузить данные

- + diff --git a/js/functions.js b/js/functions.js new file mode 100644 index 0000000..0db60b6 --- /dev/null +++ b/js/functions.js @@ -0,0 +1,42 @@ +// 1 +const checkLength = (str, length) => str.length <= length; +console.log(checkLength('проверяемая строка', 20)); // true +console.log(checkLength('проверяемая строка', 18)); // true +console.log(checkLength('проверяемая строка', 10)); // false + +// 2 +const isPalindrome = (str) => { + str = str.replace(/ /g, '').toLowerCase(); + let a = 0; + let b = str.length - 1; + while (a <= b) { + if (str[a] === str[b]) { + a++; + b--; + } else { + return false; + } + } + return true; +}; + +console.log(isPalindrome('топот')); // true +console.log(isPalindrome('ДовОд')); // true +console.log(isPalindrome('Кекс')); // false +console.log(isPalindrome('Лёша на полке клопа нашёл')); // true + +// 3 +const getNumbers = (input) => { + const str = input.toString(); + const numbers = str.match(/\d/g); + return numbers ? parseInt(numbers.join(''), 10) : NaN; +}; + +console.log(getNumbers('2023 год')); // 2023 +console.log(getNumbers('ECMAScript 2022')); // 2022 +console.log(getNumbers('1 кефир, 0.5 батона')); // 105 +console.log(getNumbers('агент 007')); // 7 +console.log(getNumbers('а я томат')); // NaN +console.log(getNumbers(2023)); // 2023 +console.log(getNumbers(-1)); // 1 +console.log(getNumbers(1.5)); // 15 diff --git a/js/main.js b/js/main.js index e69de29..99dcea8 100644 --- a/js/main.js +++ b/js/main.js @@ -0,0 +1,24 @@ +import './scale'; +import './slider'; + + +const imageInput = document.getElementById('upload-file'); +const uploadOverlay = document.querySelector('.img-upload__overlay'); +const closeBtn = document.getElementById('upload-cancel'); +document.addEventListener('keydown', (evt) => { + if (evt.key === 'Escape') { + closeEditModal(); + } +}); +closeBtn.addEventListener('click', closeEditModal); +imageInput.addEventListener('change', openEditModal); + +function openEditModal() { + uploadOverlay.classList.remove('hidden'); + document.body.classList.add('modal-open'); +} +function closeEditModal() { + uploadOverlay.classList.add('hidden'); + document.body.classList.remove('modal-open'); +} +