script.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. function a(){
  2. alert("Привет!");
  3. }
  4. a()
  5. //
  6. function cube(){
  7. console.log(prompt(`число`)**3);
  8. }
  9. cube();
  10. //
  11. function avg2 (a, b){
  12. console.log((a + b) / 2);
  13. }
  14. avg2(1,2);
  15. avg2(10,5);
  16. //
  17. function sum3 (a, b, c){
  18. a = a || 0;
  19. b = b || 0;
  20. c = c || 0;
  21. return(a + b + c);
  22. }
  23. sum3(1,2,3);
  24. sum3(5,10,100500);
  25. sum3(5,10);
  26. //
  27. function intRandom (a, b){
  28. a = a || 0;
  29. b = b || 0;
  30. let number = (Math.random() * (b - a) + a);
  31. return Math.round(number);
  32. }
  33. console.log(intRandom(2, 15))
  34. console.log(intRandom(-1, -1))
  35. console.log(intRandom(0, 1))
  36. console.log(intRandom(10))
  37. //
  38. function greetAll() {
  39. let mans = "";
  40. for(i = 0; i<arguments.length;i++) {
  41. mans += "," + " " + arguments[i]
  42. }
  43. alert(`Hello ${mans}`)
  44. }
  45. greetAll("Superman")
  46. greetAll("Superman", "SpiderMan")
  47. greetAll("Superman", "SpiderMan", "Captain Obvious")
  48. //
  49. function sum (){
  50. let resulta = 0;
  51. for(let i of arguments){
  52. resulta += i;
  53. }
  54. console.log(resulta);
  55. }
  56. sum(1)
  57. sum(2)
  58. sum(10, 20, 40, 100)
  59. //
  60. function aSample(){
  61. a("Привет!") // вызывает alert("Привет!")
  62. }
  63. function cubeSample(){
  64. cube(5) // => 125
  65. }
  66. let sample = prompt("Введите название задания")
  67. switch (sample.toLowerCase()){
  68. case "a": a()
  69. break
  70. case "cube": cube()
  71. break
  72. case "avg2": avg2()
  73. break
  74. case "sum3": sum3()
  75. break
  76. case "intRandom": intRandom()
  77. break
  78. case "greetAll": greetAll()
  79. break
  80. case "sum": sum()
  81. break
  82. }
  83. //
  84. let sampl = {
  85. a: a(),
  86. cube: cube(),
  87. avg2: avg2(),
  88. sum3: sum3(),
  89. intRandom: intRandom(),
  90. greetAll: greetAll(),
  91. sum: sum()
  92. }
  93. let sampl1 = prompt("Введите название функции")
  94. alert(sampl1[`${sampl}`])