index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>HW-6</title>
  8. </head>
  9. <body>
  10. <script>
  11. //a
  12. function a() {
  13. alert("привет!!!")
  14. }
  15. a()
  16. //cube
  17. function cube(a) {
  18. return a ** 3;
  19. }
  20. alert(cube());
  21. alert(cube(3));
  22. //avg2
  23. function avg2(a, b) {
  24. return (a + b) / 2;
  25. }
  26. alert(avg2(1, 2))
  27. alert(avg2(10, 5))
  28. //sum3
  29. function sum3(a, b, c) {
  30. a = a || 0
  31. b = b || 0
  32. c = c || 0
  33. return (a + b + c)
  34. }
  35. alert(sum3(1, 2, 3));
  36. alert(sum3(5, 10, 100500));
  37. alert(sum3(5, 10));
  38. //intRandom
  39. function intRandom(a, b) {
  40. a = a || 0
  41. b = b || 0
  42. return Math.round(Math.random() * (b - a) + a);
  43. }
  44. alert(intRandom(2, 15));
  45. alert(intRandom(-1, -1));
  46. alert(intRandom(0, 1));
  47. alert(intRandom(10));
  48. //greetAll
  49. function greetAll(...params) {
  50. let add = "";
  51. for (i = 0; i < params.length; i++) {
  52. add += params[i] + " "
  53. }
  54. return alert("Hello " + add)
  55. }
  56. greetAll("Superman")
  57. greetAll("Superman", "SpiderMan")
  58. greetAll("Superman", "SpiderMan", "Captain Obvious")
  59. //sum
  60. function sum(...numbers) {
  61. var sum = 0;
  62. for (i = 0; i < numbers.length; i++) {
  63. sum += numbers[i];
  64. }
  65. return sum;
  66. }
  67. alert(sum(1))
  68. alert(sum(2))
  69. alert(sum(10, 20, 40, 100))
  70. //Union
  71. var sample = prompt("Введите название задания")
  72. switch (sample.toLowerCase()) {
  73. case "a":
  74. a()
  75. break
  76. case "cube":
  77. cube()
  78. break
  79. case "avg2":
  80. avg2()
  81. break;
  82. case "sum3":
  83. sum3()
  84. break;
  85. case "intRandom":
  86. intRandom()
  87. break;
  88. case "greetAll":
  89. greetAll()
  90. break
  91. case "sum":
  92. sum()
  93. break;
  94. }
  95. //Union declarative
  96. let sample2 = {
  97. a(){
  98. a("Привет")
  99. },
  100. cube() {
  101. cube(3)
  102. },
  103. avg2() {
  104. avg2(1 ,2)
  105. },
  106. sum3() {
  107. sum3(5, 10, 100500)
  108. },
  109. intRandom() {
  110. intRandom(-1, -1)
  111. },
  112. greetAll() {
  113. greetAll("Superman", "SpiderMan")
  114. },
  115. sum() {
  116. sum(10, 20, 40, 100)
  117. },
  118. }
  119. console.log(sample2[prompt("Введите название задания")]());
  120. </script>
  121. </body>
  122. </html>