script.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. function a() {
  3. return alert("Привет!");
  4. }
  5. function cube(num) {
  6. return console.log(Math.pow(num, 3));
  7. }
  8. function avg2(a, b) {
  9. return console.log((a + b) / 2)
  10. }
  11. function sum3(a, b, c) {
  12. return console.log(a + b + c || a + b)
  13. }
  14. function intRandom(min, max) {
  15. min = Math.ceil(min);
  16. max = Math.floor(max);
  17. return console.log(Math.floor(Math.random() * (max - min)) + min + 1 || Math.floor(Math.random() * min) + 1);
  18. }
  19. function greetAll() {
  20. let ani = "Hello";
  21. for (let key of arguments) {
  22. ani = `${ani} ${key},`;
  23. }
  24. return alert(ani.substring(0, ani.length - 1))
  25. }
  26. function sum() {
  27. let total = 0;
  28. for (let key of arguments) {
  29. total += key;
  30. }
  31. return console.log(total);
  32. }
  33. let task = prompt("Введите название задания", "");
  34. switch (task.toLocaleLowerCase()) {
  35. case "a":
  36. a();
  37. break;
  38. case "cube":
  39. cube(3)
  40. break;
  41. case "avg2":
  42. avg2(1, 2);
  43. avg2(10, 5);
  44. break;
  45. case "sum3":
  46. sum3(1, 2, 3);
  47. sum3(5, 10, 100500);
  48. sum3(5, 10);
  49. break;
  50. case "intrandom":
  51. intRandom(2, 10);
  52. break;
  53. case "greetall":
  54. greetAll("Superman");
  55. greetAll("Superman", "SpiderMan");
  56. greetAll("Superman", "SpiderMan", "Captain Obvious");
  57. break;
  58. case "sum":
  59. sum(1);
  60. sum(2);
  61. sum(10, 20, 40, 100);
  62. break;
  63. default:
  64. alert('Неизвестное значение');
  65. }
  66. function unionDeclarative() {
  67. let task = {
  68. a: () => a(),
  69. cube: () => cube(3),
  70. avg2: () => {
  71. avg2(1, 2);
  72. avg2(10, 5)
  73. },
  74. sum3: () => {
  75. sum3(1, 2, 3);
  76. sum3(5, 10, 100500);
  77. sum3(5, 10);
  78. },
  79. intrandom: () => intRandom(2, 10),
  80. greetall: () => {
  81. greetAll("Superman");
  82. greetAll("Superman", "SpiderMan");
  83. greetAll("Superman", "SpiderMan", "Captain Obvious");
  84. },
  85. sum: () => sum(10, 20, 40, 100),
  86. }
  87. task[prompt("Введите название задания", "").toLocaleLowerCase()]();
  88. }
  89. // unionDeclarative()