main.js 2.1 KB

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