← Back to challenges

Summing the Squares

JavaScriptHardloopsnumberslanguage_fundamentalsmath

Instructions

Create a function that takes a number n and returns the sum of all square numbers up to and including n.

squaresSum(3) ➞ 14
// 1² + 2² + 3² =
// 1 + 4 + 9 =
// 14

Examples

squaresSum(3) ➞ 14

squaresSum(12) ➞ 650

squaresSum(13) ➞ 819

Notes

Remember that n is included in the total.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Scottish Screaming