main.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // a
  2. function a() {
  3. alert('Привет');
  4. }
  5. a()
  6. // cube
  7. function cube() {
  8. console.log(prompt('number') ** 3);
  9. }
  10. cube()
  11. // avg2
  12. function avg2(a, b) {
  13. console.log((a + b) / 2);
  14. }
  15. avg2(5, 10)
  16. avg2(1, 2)
  17. // sum3
  18. function sum3(a, b, c) {
  19. a = a || 0;
  20. b = b || 0;
  21. c = c || 0;
  22. return a + b + c;
  23. }
  24. console.log(sum3(1, 2, 3))
  25. console.log(sum3(5, 10, 100500))
  26. console.log(sum3(5, 10))
  27. // intRandom
  28. function intRandom(min, max) {
  29. min = min || 0;
  30. max = max || 0;
  31. let result = Math.random() * (max - min) + min;
  32. return Math.round(result)
  33. }
  34. console.log(intRandom(2, 15))
  35. console.log(intRandom(-1, -1))
  36. console.log(intRandom(0, 1))
  37. console.log(intRandom(10))
  38. // greetAll
  39. function greetAll(...arguments) {
  40. for (let arg of arguments) {
  41. alert(`Hello ${arg}!`)
  42. }
  43. }
  44. greetAll("Superman")
  45. greetAll("Superman", "SpiderMan")
  46. greetAll("Superman", "SpiderMan", "Captain Obvious")
  47. // sum
  48. function sum(...arguments) {
  49. let result = 0
  50. for (let arg of arguments) {
  51. result += arg
  52. }
  53. console.log(result)
  54. }
  55. sum(1)
  56. sum(2)
  57. sum(10, 20, 40, 100)
  58. // Union