← Back to challenges

House of Cards

JavaScriptHardmathnumbers

Instructions

The image below shows a sequence of larger and larger houses of cards, with the total number of cards included for each:

House of Cards

Given the tower height n, return the number of cards needed to construct a full house of cards.

Examples

cardsNeeded(3) ➞ 15

cardsNeeded(4) ➞ 26

cardsNeeded(0) ➞ 0

Notes

The height should always be equal or greater than 0. Return "invalid" if the value given doesn't abide by this rule.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Multidimensional Array into Single Dimensional Array