main.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. function a (text="called function alert") {
  2. alert(text);
  3. }
  4. /* a("hello"); */
  5. /* function cube (number) {
  6. return number **3;
  7. }
  8. a(cube(3)); */
  9. /* function avg(a,b){
  10. return ((a+b)/2);
  11. }
  12. a(avg(1,2));
  13. a(avg(10,5)); */
  14. /* function sum3 (a=0,b=0,c=0) {
  15. return a+b+c;
  16. }
  17. a(sum3(1,2,3));
  18. a(sum3(5,10,100500));
  19. a(sum3(10,5)); */
  20. /* function intRandom (min,max=0) {
  21. if(max == 0 ){
  22. return Math.floor(Math.random()* (min-max+1))+max;
  23. }
  24. return Math.floor(Math.random()* (max-min+1))+min;
  25. }
  26. a(intRandom(100)); */
  27. /* function greetAll(...names) {
  28. let greetArr = [];
  29. for(let i = 0 ; i< arguments.length; i++){
  30. greetArr.push(names[i]);
  31. }
  32. alert(greetArr);
  33. }
  34. greetAll("SPYDIK","KYRKA","VETAL"); */
  35. function sum(...numarr){
  36. /* let result=0;
  37. for(let i =0; i<arguments.length;i++){
  38. debugger;
  39. result=result+arguments[i];
  40. }
  41. alert(result); */
  42. let arrforsum = [];
  43. for(let i = 0; i<arguments.length; i++){
  44. arrforsum.push(numarr[i]);
  45. }
  46. let sum = 0 ;
  47. for(let i =0; i<arrforsum.length;i++){
  48. sum=sum+arrforsum[i];
  49. }
  50. alert(sum);
  51. /* return alert(numarr.reduce((a,b) => a+b)); */
  52. }
  53. sum(...[10,2,20]);