Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Решения
- ```js
- // 1. Сумма
- function sum(a, b) {
- return a + b;
- }
- // 2. Произведение (анонимная)
- const multiply = function(x, y) {
- return x * y;
- };
- // 3. Задержка alert
- setTimeout(function() {
- alert('Привет!');
- }, 1000);
- // 4. Вывод arguments
- function showArgs() {
- console.log(arguments);
- }
- showArgs(1, 'a', true);
- // 5. Смена фона
- function changeBgColor(selector, color) {
- const el = document.querySelector(selector);
- if (el) el.style.backgroundColor = color;
- }
- // 6. Добавление абзаца
- function addParagraph(containerSel, text) {
- const container = document.querySelector(containerSel);
- if (container) container.innerHTML += '<p>' + text + '</p>';
- }
- // 7. Переключение видимости
- function toggleVisibility(selector) {
- const el = document.querySelector(selector);
- if (el) {
- el.style.display = (el.style.display === 'none') ? '' : 'none';
- }
- }
- // 8. Изменение размера
- function resizeElement(selector, width, height) {
- const el = document.querySelector(selector);
- if (el) {
- el.style.width = width;
- el.style.height = height;
- }
- }
- // 9. Случайное число
- function randomBetween(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- // 10. Отложенная смена фона
- function delayedBgChange(selector, color, delay) {
- const el = document.querySelector(selector);
- if (el) {
- setTimeout(function() {
- el.style.backgroundColor = color;
- }, delay);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement