JS基础语法---函数练习part1---5个练习

练习1:求两个数字的和:获取任意的两个数字的和

      function getSum(x, y) {
        return x + y;
      }
      console.log(getSum(10, 20));

 

练习2:求1-100之间所有的数字的和

      function geteverySum() {
        var sum = 0;
        for (var i = 1; i <= 100; i++) {
          sum += i;
        }
        return sum;
      }
      console.log(geteverySum());

 

练习3:求1-n之间所有数的和

      function geteverySum(n) {
        var sum = 0;
        for (var i = 0; i <= n; i++) {
          sum += i;
        }
        return sum;
      }
      console.log(geteverySum(89));

 

练习4:求n-m之间所有数的和

      function geteverySum2(n,m) {
        var sum = 0;
        for (var i = n; i <= m; i++) {
          sum += i;
        }
        return sum;
      }
      console.log(geteverySum2(32,90));

 

练习5:求圆的面积

      function geteverySum2(n,m) {
        var sum = 0;
        for (var i = n; i <= m; i++) {
          sum += i;
        }
        return sum;
      }
      console.log(geteverySum2(32,90));

 

 

 

posted @ 2019-11-26 17:15  jane_panyiyun  阅读(466)  评论(0编辑  收藏  举报