Javascript - Challenge
Code Life
By Pierre Marsaa
Potion Shop
Sam walks into the potion shop. Potions cost 30 gold each. You'll write two small functions, then use them to handle Sam's purchase.
Step 1: write price(quantity). It receives a number of potions and returns the total cost. For example, price(2) returns 60.
Step 2: write canAfford(gold, total). It receives the gold Sam has and a total to pay, and returns true if the gold is enough, false otherwise. For example, canAfford(50, 60) returns false.
Step 3: Sam has gold and wants wanted potions. Use your two functions to print "Total: X gold", then "Deal!" if Sam can pay, or "Not enough gold" if not.
Expected output:
Loading editor...
↗️
Loading editor...
↶
↷
💡 Show Solution
Continue