swati-jagtap / javascript-practice

0 stars 0 forks source link

7.2.12-- Declare a function name sumOfEven. It takes a number parameter and it adds all the even numbers in that - range. #82

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago

7.2.12--Declare a function name sumOfEven. It takes a number parameter and it adds all the even numbers in that - range.

function sumOfEvens(n)
{
    let sum=0;
    for(i=0;i<=n;i=i+2)
    {
          sum+=i;
    }
    return `Sum of even no. in the range  ${n}=${sum}`;
}
console.log(sumOfEvens(20));
console.log(sumOfEvens(4));

output

image