Sum of the Odd Numbers

Published by Mubashir Hassan in

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!

Watch a quick demo on how Edabit works.