Js-HW6.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. function a(text) {
  2. alert(text)
  3. }
  4. function cube(n) {
  5. return Math.pow(n, 3)
  6. }
  7. function avg2(a, b) {
  8. return (a + b) / 2
  9. }
  10. function sum3(a, b, ...c) {
  11. return a + b + +c
  12. }
  13. function intRandom(min = 0, max = 10) {
  14. return Math.round(Math.random() * (max - min - 1) + min)
  15. }
  16. // function greetAll(...arguments) {
  17. // for(let arg of arguments) {
  18. // alert(`Hello, ${arg}!`)
  19. // }
  20. // }
  21. function greetAll(...arguments) {
  22. arguments = arguments.map(item => ' ' + item)
  23. alert(`Hello, ${arguments}!`)
  24. }
  25. function sum(...arguments) {
  26. let result = 0
  27. for(let num of arguments) {
  28. result += num
  29. }
  30. return result
  31. }
  32. var sample = prompt("Введите название задания")
  33. switch (sample.toLowerCase()){
  34. case "a": a('Test prompt')
  35. break
  36. case "cube": cube(5)
  37. break
  38. case 'avg2': avg2(55, 17)
  39. break
  40. case 'sum3': sum3(5, 82, 47)
  41. break
  42. case 'intRandom': intRandom(1, 105)
  43. break
  44. case 'greetAll': greetAll('Sonya', 'Kerry', 'Eve')
  45. break
  46. case 'sum': sum(45, 741, 32, 14)
  47. break
  48. default:
  49. a()
  50. }
  51. let sampleObj = {
  52. a() {
  53. a('Test prompt')
  54. },
  55. cube() {
  56. cube(50)
  57. },
  58. avg2() {
  59. avg2(55, 17)
  60. },
  61. sum3() {
  62. sum3(5, 82, 47)
  63. },
  64. intRandom() {
  65. intRandom(1, 50)
  66. },
  67. greetAll() {
  68. greetAll('Sonya', 'Kerry', 'Eve')
  69. },
  70. sum() {
  71. sum(45, 741, 32, 14)
  72. },
  73. };
  74. console.log(sampleObj[prompt("Введите название задания")]());