5 XP challenge
Shop with Rising Prices
very easy
Build it yourself · 3 min
1 Learn2 Predict3 Solve
TaskYour mission
The days input gives the maximum number of purchases. Buy one item per day at price startingPrice + dayIndex * increase, with dayIndex starting at 0. Stop at the first unaffordable item. Return how many items were bought. budget is 0 to 100; startingPrice is 1 to 20; increase is 0 to 10; days is 0 to 10.
Examples
| Input | Return |
|---|---|
budget = 20, startingPrice = 3, increase = 2, days = 5count: 0 → 1 → 2 → 3. shopping: true → false. price: 3 → 5 → 7 → 9 → 11. The result is 3. | 3 |
budget = 10, startingPrice = 5, increase = 0, days = 5remaining: 10 → 5 → 0. count: 0 → 1 → 2. shopping: true → false. The result is 2. | 2 |
Your code
Write your answer inside Solution, then use return to send it back.
Ln 1, Col 1
JavaScript
Try examples runs the public examples. Check my code checks your full answer and saves your completion.