練習1:求兩個數字的和:獲取任意的兩個數字的和 function getSum(x, y) { return x + y; } console.log(getSum(10, 20)); 練習2:求1-100之間所有的數字的和 function geteverySum() { var sum = 0; ...
練習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));