Dz6js.html 3.0 KB

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