Find the sum of all the numbers between n-m and the sum of 1-100 and

求1-100 and

<script type="text/javascript">
            var sum = 0;
            for (var i = 0;i<=100;i++) {
                sum += i;
            }
            console.log(sum)
        </script>

求n-m and the sum between

求n-m: In the above code, although the parameter is not added, it can achieve the sum between 1-100, but the function is a closed environment. If you want to add any number, we can use the parameter to the outside. The value is passed inside the function

<script type="text/javascript">
            var a = 1; b = 5;
            var sum = 0;
            addsum(a, b);
            function addsum(n, m) {
                for (var i=n;n<=m;n++) {
                    sum = sum+n
                }
                console.log(sum)
            }
        </script>