JavaScript Exercises Basic#4 - Sum up to N

JavaScript Exercises Basic#4 - Sum up to N

Write a program which returns the sum of numbers from 1 to N

Solution

function solution(N){
                let sum = 0;
                for (let i = 1; i <= N; i++){
                    sum = sum + i;
                }

                return sum;
            }

Result

Screenshot 2022-04-12 at 21.26.14.png