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. //
  36. //sum
  37. function sum(array){
  38. var a = 0;
  39. for (let i = 0; i < arguments.length;i++){
  40. a += arguments[i]
  41. }
  42. return a;
  43. }
  44. //UNION
  45. function aSample(){
  46. console.log(a())
  47. }
  48. function cubeSample(){
  49. console.log(cube(5))
  50. }
  51. function avg2Sample(){
  52. console.log(avg2(20,50))
  53. }
  54. function sum3Sample(){
  55. console.log(sum3(5,10))
  56. }
  57. function intRandomSample(){
  58. console.log(intRandom(2,15))
  59. }
  60. function greetAllSample(){
  61. console.log(greetAll("Spiderman","Superman"))
  62. }
  63. function sumSample(){
  64. console.log(sum(20,40,60,80,100))
  65. }
  66. // var sample = prompt("Введите название задания")
  67. // switch (sample.toLowerCase()){
  68. // case "a": aSample()
  69. // break
  70. // case "cube": cubeSample();
  71. // break
  72. // case "avg2": avg2Sample();
  73. // break
  74. // case "sum3": sum3Sample();
  75. // break
  76. // case "intrandom": intRandomSample();
  77. // break
  78. // case "greetall": greetAllSample("Superman","SpiderMan")
  79. // break
  80. // case "sum":sumSample();
  81. // break
  82. // }
  83. //UNION declarative
  84. let union = {
  85. a(){
  86. console.log(a())
  87. },
  88. cube(){
  89. console.log(cube(5))
  90. },
  91. avg2(){
  92. console.log(avg2(20,50))
  93. },
  94. sum3(){
  95. console.log(sum3(5,10))
  96. },
  97. intRandom(){
  98. console.log(intRandom(2,15))
  99. },
  100. greetAll(){
  101. console.log(greetAll("Spiderman","Superman"))
  102. },
  103. sum(){
  104. console.log(sum(20,40,60,80,100))
  105. },
  106. };
  107. console.log(union[prompt("Введите название задания")]());
  108. </script>
  109. </body>
  110. </html>