← Back to challenges

Sum of the Odd Numbers

JavaScriptHardmathloops

Instructions

Create a function which returns the total of all odd numbers up to and including n. n will be given as an odd number.

Examples

addOddToN(5) ➞ 9
// 1 + 3 + 5 = 9

addOddToN(13) ➞ 49

addOddToN(47) ➞ 576

Notes

Curiously, the answers are all square numbers!

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: The Study of Wumbology