marinvch

11. Sum of Odd Numbers

Sep 26th, 2018
171
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. }
RAW Paste Data