main.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // a
  2. function a() {
  3. alert('Привет');
  4. }
  5. // cube
  6. function cube(number) {
  7. number = number ** 3;
  8. return number;
  9. }
  10. // avg2
  11. function avg2(a = 0, b = 0) {
  12. let avg = (a + b) / 2;
  13. return avg;
  14. };
  15. // sum3
  16. function sum3(a = 0, b = 0, c = 0) {
  17. let sum = (a + b + c);
  18. return sum;
  19. }
  20. // intRandom
  21. function intRandom(a = 0, b = 0) {
  22. let randomNumber = Math.random() * (b - a) + a;
  23. return Math.round(randomNumber);
  24. };
  25. // greetAll
  26. function greetAll() {
  27. for (let i = 0; i < arguments.length; i++) {
  28. alert("Hello, " + arguments[i]);
  29. };
  30. };
  31. // sum
  32. function sum() {
  33. let result = 0;
  34. for (let i = 0; i < arguments.length; i++) {
  35. result += arguments[i];
  36. }
  37. return result;
  38. }
  39. // Union
  40. function aSample() {
  41. return a("Привет!");
  42. }
  43. function cubeSample() {
  44. return cube(5);
  45. }
  46. function avg2Sample() {
  47. return avg2(10, 5);
  48. }
  49. function sum3Sample() {
  50. return sum3(2, 4, 6);
  51. }
  52. function intRandomSample() {
  53. return intRandom(0, 1);
  54. }
  55. function greetAllSample() {
  56. return greetAll("Superman", "SpiderMan", "Captain Obvious");
  57. }
  58. function sumSample() {
  59. return sum(10, 20, 40, 100);
  60. }
  61. var taskName = prompt("Введите название задания");
  62. switch (taskName.toLowerCase()) {
  63. case "a":
  64. aSample();
  65. break;
  66. case "cube":
  67. cubeSample();
  68. break;
  69. case "avg2":
  70. avg2Sample();
  71. break;
  72. case "sum3":
  73. sum3Sample();
  74. break;
  75. case "intRandom":
  76. intRandomSample();
  77. break;
  78. case "greetAll":
  79. greetAllSample();
  80. break;
  81. case "sum":
  82. sumSample();
  83. break;
  84. }
  85. // Union declarative
  86. let unionDeclarative = {
  87. a: aSample(),
  88. cube: cubeSample(),
  89. avg2: avg2Sample(),
  90. sum3: sum3Sample(),
  91. intRandom: intRandomSample(),
  92. greetAll: greetAllSample(),
  93. sum: sumSample()
  94. }