← Back to challenges

Sum of Cubes

JavaScriptHardnumbersmathlanguage_fundamentalsalgorithms

Instructions

Create a function that takes a positive integer n, and returns the sum of all the cubed values from 1 to n.

For example, if n is 3:

sumCubes(3) ➞ 36
1 ** 3 + 2 ** 3 + 3 ** 3 = 36

Examples

sumCubes(7) ➞ 784

sumCubes(8) ➞ 1296

sumCubes(9) ➞ 2025

Notes

Input n will be a positive integer.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Sum of Numbers in an Array