Created
July 20, 2021 20:49
-
-
Save diasraphael/1faa8c0dab6539586832e78beefee5ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rowSumOddNumbers(n) { | |
let startValue = n * (n - 1) + 1; | |
let sum = 0; | |
for (let i = 1; i <= n; i++) { | |
if (i == 1) { | |
sum = startValue | |
} else { | |
startValue = startValue + 2; | |
sum = sum + startValue; | |
} | |
} | |
return sum; | |
} | |
console.log(rowSumOddNumbers(4)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment