Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Нужно больше функций #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ <h2 class="success__title">Изображение успешно загруже
<h2 class="data-error__title">Не удалось загрузить данные</h2>
</section>
</template>

<script type="module" src="./js/functions.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 1
const checkLength = (str, length) => str.length <= length;
console.log(checkLength('проверяемая строка', 20)); // true

Check failure on line 3 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(checkLength('проверяемая строка', 18)); // true

Check failure on line 4 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(checkLength('проверяемая строка', 10)); // false

Check failure on line 5 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement

// 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

Check failure on line 23 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(isPalindrome('ДовОд')); // true

Check failure on line 24 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(isPalindrome('Кекс')); // false

Check failure on line 25 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(isPalindrome('Лёша на полке клопа нашёл')); // true

Check failure on line 26 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement

// 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

Check failure on line 35 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(getNumbers('ECMAScript 2022')); // 2022

Check failure on line 36 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(getNumbers('1 кефир, 0.5 батона')); // 105

Check failure on line 37 in js/functions.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
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
24 changes: 24 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -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');
}

Loading