index.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. //a
  12. function a(){
  13. alert("Привет");
  14. }
  15. //cube
  16. var cube = a => a ** 3
  17. //avg2
  18. var avg2 = (a , b) => (a + b)/2;
  19. //sum3
  20. function sum3(a = 0, b = 0, c = 0) {
  21. let sums = a + b + c;
  22. return sums;
  23. }
  24. //intRandom
  25. function intRandom(a = 0, b = 0) {
  26. let random = Math.random() * (b - a) + a;
  27. return Math.floor(random);
  28. }
  29. //greetAll
  30. function greetAll(){
  31. for (var i = 0;i < arguments.length;i++){
  32. arr = alert('Hi ,' + arguments[i])
  33. }
  34. }
  35. //sum
  36. function sum(array){
  37. var a = 0;
  38. for (let i = 0; i < arguments.length;i++){
  39. a += arguments[i]
  40. }
  41. return a;
  42. }
  43. //UNION
  44. function aSample(){
  45. console.log(a())
  46. }
  47. function cubeSample(){
  48. console.log(cube(5))
  49. }
  50. function avg2Sample(){
  51. console.log(avg2(20,50))
  52. }
  53. function sum3Sample(){
  54. console.log(sum3(5,10))
  55. }
  56. function intRandomSample(){
  57. console.log(intRandom(2,15))
  58. }
  59. function greetAllSample(){
  60. console.log(greetAll("Spiderman","Superman"))
  61. }
  62. function sumSample(){
  63. console.log(sum(20,40,60,80,100))
  64. }
  65. // var sample = prompt("Введите название задания")
  66. // switch (sample.toLowerCase()){
  67. // case "a": aSample()
  68. // break
  69. // case "cube": cubeSample();
  70. // break
  71. // case "avg2": avg2Sample();
  72. // break
  73. // case "sum3": sum3Sample();
  74. // break
  75. // case "intrandom": intRandomSample();
  76. // break
  77. // case "greetall": greetAllSample("Superman","SpiderMan")
  78. // break
  79. // case "sum":sumSample();
  80. // break
  81. // }
  82. //UNION declarative
  83. let union = {
  84. a(){
  85. console.log(a())
  86. },
  87. cube(){
  88. console.log(cube(5))
  89. },
  90. avg2(){
  91. console.log(avg2(20,50))
  92. },
  93. sum3(){
  94. console.log(sum3(5,10))
  95. },
  96. intRandom(){
  97. console.log(intRandom(2,15))
  98. },
  99. greetAll(){
  100. console.log(greetAll("Spiderman","Superman"))
  101. },
  102. sum(){
  103. console.log(sum(20,40,60,80,100))
  104. },
  105. };
  106. console.log(union[prompt("Введите название задания")]());
  107. </script>
  108. </body>
  109. </html>