Advertisement
marinvch

11. Sum of Odd Numbers

Sep 26th, 2018
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(n) {
  2.     let counter = Number(n);
  3.     let sum = 0;
  4.     let odd = 1;
  5.  
  6.  
  7.     for (let i = 1; i <= counter; i++) {
  8.         sum += odd;
  9.         console.log(odd);
  10.         odd += 2
  11.     }
  12.     console.log(`Sum: ${sum}`)
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement