Skip to main content

Practice · 1 of 3

The candy machine lifecycle

CHALLENGE
Difficulty: advanced+25 XP

Implement CandyMachine: constructor takes the starting candy count (coins start at 0). buy() dispenses one candy and takes one coin — returns false (changing nothing) when out of candy. restock(n) adds n candies, allowed at any time. emptyCoins() returns the collected coins and **resets the coin count to zero**.

Back to lesson: Practice: Class design gauntlet