index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* a */
  2. function a(text){
  3. alert(text)
  4. }
  5. a("Привет!")
  6. /* cube */
  7. function cube(number){
  8. return number ** 3
  9. }
  10. let result = cube(prompt('Enter a number'))
  11. console.log(result)
  12. /* avg2 */
  13. function avg2(a1, b1) {
  14. return (a1 + b1) / 2
  15. }
  16. let a1 = +prompt('Enter a number')
  17. let b1 = +prompt('Enter a number')
  18. avg2(a1, b1)
  19. /* sum3 */
  20. function sum3(a2 = 0, b2 = 0, c2 = 0) {
  21. let sum1 = (a2 + b2 + c2)
  22. return sum1
  23. }
  24. sum3(a2, b2, c2)
  25. /* intRandom */
  26. function intRandom(a3, b3) {
  27. let random = Math.random()* (b3-a3) + a3
  28. return Math.round(random)
  29. }
  30. let a3 = +prompt('Enter a number')
  31. let b3 = +prompt('Enter a number')
  32. intRandom(a3, b3)
  33. /* greetAll */
  34. function greetAll() {
  35. let greetAll1 = " "
  36. for (let i = 0; i < arguments.length; i++) {
  37. greetAll1 += " " + arguments[i] + ","
  38. }
  39. alert("Hello, " + greetAll1);
  40. }
  41. greetAll("superman", "Spiderman", "Бетмен")
  42. /* sum */
  43. function sum(a4, b4, c4) {
  44. let sum = 0;
  45. for (let i = 0; i < arguments.length; i++) {
  46. sum += arguments[i];
  47. }
  48. return sum
  49. }
  50. a4 = +prompt('Enter a number')
  51. b4 = +prompt('Enter a number')
  52. c4 = +prompt('Enter a number')
  53. sum(a4, b4, c4)
  54. /* Union */
  55. function aSample(){
  56. a("Привет!")
  57. }
  58. function cubeSample(){
  59. cube(5)
  60. }
  61. function avg2Sample(){
  62. avg2(2, 2)
  63. }
  64. function sum3Sample(){
  65. sum3(1, 2, 3)
  66. }
  67. function intRandomSample(){
  68. intRandom(2,10)
  69. }
  70. function greetAllSample() {
  71. greetAll('Superman')
  72. }
  73. function sumSample(){
  74. sum(1,4,7)
  75. }
  76. var sample = prompt("Введите название задания")
  77. switch (sample.toLowerCase()){
  78. case "a": aSample()
  79. break;
  80. case "cube": cubeSample()
  81. break;
  82. case "avg2": avg2Sample()
  83. break;
  84. case "sum3": sum3Sample()
  85. break;
  86. case "intRandom": intRandomSample()
  87. break;
  88. case "greetAll": greetAllSample()
  89. break;
  90. case "sum": sumSample()
  91. break;
  92. }
  93. /* Union declarative */
  94. let unionDeclarative = {
  95. a(){
  96. a("Привет!")
  97. },
  98. cube(){
  99. cube(5)
  100. },
  101. avg2(){
  102. avg2(2, 2)
  103. },
  104. sum3(){
  105. sum3(1, 2, 3)
  106. },
  107. intRandom(){
  108. intRandom(2,10)
  109. },
  110. greetAll(){
  111. greetAll('Superman')
  112. },
  113. sum() {
  114. sum(1, 4, 7)
  115. }
  116. }