silvana1303

sum of odd numbers

Apr 5th, 2021
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function odd(num){
  2.     let count = 0;
  3.     let sum = 0;
  4.     for (let i=1; i <= 100; i++){
  5.         if (i % 2 == 1) {
  6.             console.log(i);
  7.  
  8.             count++;
  9.             sum += i;
  10.             if (count==num){
  11.                 break;
  12.             }
  13.  
  14.         }
  15.  
  16.     }
  17.  
  18.     console.log(`Sum: ${sum}`)
  19. }
Advertisement
Add Comment
Please, Sign In to add comment