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