main.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //a
  2. let a = function(str) {
  3. alert(str);
  4. }
  5. //cube
  6. let cube = function(number) {
  7. return Math.pow(number, 3);
  8. }
  9. //avg2
  10. let getMeanValue = function(numberA, numberB) {
  11. return (numberA + numberB) / 2;
  12. }
  13. //sum3
  14. let sum3 = function(number1 = 0, number2 = 0, number3 = 0) {
  15. return number1 + number2 + number3;
  16. }
  17. //intRandom
  18. let intRandom = function(bottomValue, topValue) {
  19. return (Math.random() * topValue + bottomValue);
  20. }
  21. //greetAll
  22. let greetAll = function(...name) {
  23. alert(`Hello ${name.join(", ")}`);
  24. }
  25. //sum
  26. let sum = function(...arr) {
  27. let sumArrElement = 0;
  28. for(let item of arr) {
  29. sumArrElement += item;
  30. }
  31. return sumArrElement;
  32. }
  33. //Union
  34. var sample = prompt("Введите название задания");
  35. switch (sample.toLowerCase()){
  36. case "a": a("Привет");
  37. break;
  38. case "cube": console.log(cube(5));
  39. break;
  40. case "avg2": console.log(getMeanValue(10, 5));
  41. break;
  42. case "sum3": console.log(sum3(5, 10));
  43. break;
  44. case "intRandom": console.log(intRandom(2, 15));
  45. console.log(intRandom(-1, -1));
  46. console.log(intRandom(0, 1));
  47. console.log(intRandom(0, 10));
  48. break;
  49. case "greetAll": greetAll("Superman");
  50. greetAll("Superman", "SpiderMan");
  51. greetAll("Superman", "SpiderMan", "Captain Obvious");
  52. break;
  53. case "sum": console.log(sum(1)); // => 1
  54. console.log(sum(2)); // => 2
  55. console.log(sum(10,20,40,100)); // => 170
  56. break;
  57. default: alert("Такого задания нет");
  58. }
  59. //Union declarative
  60. let arr = {
  61. a: a("Привет"),
  62. cube: console.log(cube(5)),
  63. avg2: console.log(getMeanValue(10, 5)),
  64. sum3: console.log(sum3(5, 10)),
  65. intRandom: console.log(intRandom(2, 15)),
  66. greetAll: greetAll("Superman"),
  67. sum: console.log(sum(1)),
  68. default: "Такого задания нет"
  69. }