file.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // a
  2. function a(){
  3. alert("Hello")
  4. }
  5. a();
  6. // cube
  7. function cube(x){
  8. return x**3;
  9. }
  10. cube();
  11. // avg2
  12. function avg2(a,b){
  13. return (a + b)/2
  14. }
  15. avg2();
  16. // sum3
  17. function sum3(a,b,c){
  18. return (a + b + c) || (a + b)
  19. }
  20. sum3();
  21. // intRandom
  22. function intRandom(a,b) {
  23. if(b === undefined){
  24. c = (Math.round(Math.random() *a))
  25. }else
  26. c = (Math.round(Math.random() * (b - a) + a));
  27. return c
  28. }
  29. intRandom()
  30. // greetAll ?
  31. let guys = "";
  32. function greetAll(){
  33. for(i = 0;i<arguments.length;i++){
  34. guys+= " " + arguments[i]};
  35. alert(`Hi, ${guys}`)
  36. }
  37. greetAll()
  38. // sum
  39. function sum(){
  40. let result = 0;
  41. for(i = 0;i<arguments.length;i++){
  42. result += arguments[i]};
  43. return result
  44. }
  45. sum()
  46. // Union
  47. function aSample(){
  48. return a()
  49. };
  50. function cubeSample(){
  51. return cube(2)
  52. };
  53. function avg2Sample(){
  54. return avg2(3,4)
  55. };
  56. function sum3Sample(){
  57. return sum3(5,6,7)
  58. };
  59. function randomSample(){
  60. return intRandom(8,12)
  61. };
  62. function greetSample(){
  63. return greetAll("Oleg","Jopa")
  64. };
  65. function sumSample(){
  66. return sum(9,10,11,12,13)
  67. };
  68. let sample = prompt('Введите задание');
  69. switch(sample.toLowerCase()){
  70. case "a": aSample()
  71. break
  72. case "cube": cubeSample()
  73. break
  74. case "avg2": avg2Sample()
  75. break
  76. case "sum3": sum3Sample()
  77. break
  78. case "intRandom": randomSample()
  79. break
  80. case "greetAll": greetSample()
  81. break
  82. case "sum": sumSample()
  83. break
  84. }
  85. // Union declarative ?
  86. let samplee = {
  87. "a": aSample(),
  88. "cube": cubeSample(),
  89. "avg2": avg2Sample(),
  90. "sum3": sum3Sample(),
  91. "intRandom": randomSample(),
  92. "greetAll": greetSample(),
  93. "sum": sumSample()
  94. }
  95. let qvestion = prompt('Какая функция?')
  96. alert(samplee[qvestion])