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));
你好,我是Jane,如果万幸对您有用,请帮忙点下推荐,谢谢啦~另外,咱们闪存见哦~