main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 sum(...arguments) {
  22. let result = 0
  23. for(let num of arguments) {
  24. result += num
  25. }
  26. return result
  27. }
  28. var sample = prompt("Введите название задания")
  29. switch (sample.toLowerCase()){
  30. case "a": a('Test prompt')
  31. break
  32. case "cube": cube(5)
  33. break
  34. case 'avg2': avg2(55, 17)
  35. break
  36. case 'sum3': sum3(5, 82, 47)
  37. break
  38. case 'intRandom': intRandom(1, 105)
  39. break
  40. case 'greetAll': greetAll('Sonya', 'Kerry', 'Eve')
  41. break
  42. case 'sum': sum(45, 741, 32, 14)
  43. break
  44. default:
  45. a()
  46. }
  47. let sampleObj = {
  48. a: a(),
  49. cube: cube(),
  50. avg2: avg2(),
  51. sum3: sum3(),
  52. intRandom: intRandom(),
  53. greetAll: greetAll(),
  54. sum: sum(),
  55. };
  56. console.log(sampleObj[prompt("Введите название задания")]);