Advertisement
Hasli4

WEB. FunctionAnswer

Jun 5th, 2025
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ## Решения
  3.  
  4. ```js
  5. // 1. Сумма
  6. function sum(a, b) {
  7.   return a + b;
  8. }
  9.  
  10. // 2. Произведение (анонимная)
  11. const multiply = function(x, y) {
  12.   return x * y;
  13. };
  14.  
  15. // 3. Задержка alert
  16. setTimeout(function() {
  17.   alert('Привет!');
  18. }, 1000);
  19.  
  20. // 4. Вывод arguments
  21. function showArgs() {
  22.   console.log(arguments);
  23. }
  24. showArgs(1, 'a', true);
  25.  
  26. // 5. Смена фона
  27. function changeBgColor(selector, color) {
  28.   const el = document.querySelector(selector);
  29.   if (el) el.style.backgroundColor = color;
  30. }
  31.  
  32. // 6. Добавление абзаца
  33. function addParagraph(containerSel, text) {
  34.   const container = document.querySelector(containerSel);
  35.   if (container) container.innerHTML += '<p>' + text + '</p>';
  36. }
  37.  
  38. // 7. Переключение видимости
  39. function toggleVisibility(selector) {
  40.   const el = document.querySelector(selector);
  41.   if (el) {
  42.     el.style.display = (el.style.display === 'none') ? '' : 'none';
  43.   }
  44. }
  45.  
  46. // 8. Изменение размера
  47. function resizeElement(selector, width, height) {
  48.   const el = document.querySelector(selector);
  49.   if (el) {
  50.     el.style.width = width;
  51.     el.style.height = height;
  52.   }
  53. }
  54.  
  55. // 9. Случайное число
  56. function randomBetween(min, max) {
  57.   return Math.floor(Math.random() * (max - min + 1)) + min;
  58. }
  59.  
  60. // 10. Отложенная смена фона
  61. function delayedBgChange(selector, color, delay) {
  62.   const el = document.querySelector(selector);
  63.   if (el) {
  64.     setTimeout(function() {
  65.       el.style.backgroundColor = color;
  66.     }, delay);
  67.   }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement