Liliana797979

sum of odd numbers - fundamentals

Mar 21st, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function OddSum(input) {
  2.     let n = Number(input);
  3.     let sum = 0;
  4.     let counter = 0;
  5.  
  6.     for (let i = 1; i <= 100; i += 2) {
  7.         console.log(i);
  8.         counter++;
  9.         sum += i;
  10.  
  11.         if (counter == n) {
  12.             console.log(`Sum: ${sum}`);
  13.             break;
  14.         }
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment