main.js 1.7 KB

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