๐Ÿš€ Everything is free โ€” help us improve! Submit feedback and shape the platform.
๐Ÿ›Debugging Missionยทbeginnerยทโฑ๏ธ 15โ€“30mยทโญ 100 XP

M-004Fix the Token Cost Calculator

Description

Nebula Corp's billing dashboard has a broken token cost calculator. The function is supposed to estimate API costs based on input tokens, output tokens, and the selected model โ€” but customers are being shown wildly wrong numbers. Some bills show $0 when they should be $5, and others are off by orders of magnitude. Find the bugs in the pricing logic and fix them before finance notices.

Symptoms

wrong-outputcalculateCost(1000, 500, 'claude-sonnet') returns -0.045 instead of 0.0105
wrong-outputMonthly estimates are 12x too high because it multiplies by 365 instead of 30
wrong-outputAll costs are 10x too high because tokens are divided by 100 instead of 1000

Expected Behavior (3)

Correct cost for 1K input + 500 output on Claude Sonnet
(1000/1000)*0.003 + (500/1000)*0.015 = 0.003 + 0.0075 = 0.0105
Input:calculateCost(1000, 500, 'claude-sonnet')
Expected:STARTS_WITH:0.01
Correct cost for GPT-4 Turbo
(2000/1000)*0.01 + (1000/1000)*0.03 = 0.02 + 0.03 = 0.05
Input:calculateCost(2000, 1000, 'gpt-4-turbo')
Expected:0.05
Monthly estimate is reasonable
costPerRequest(0.0055) * 100 * 30 = 16.5
Input:estimateMonthlyCost(100, 500, 200, 'gpt-4o')
Expected:STARTS_WITH:16.

Related Lessons

Click Run / Check to validate your solution