Skip to main content
πŸ€– Learn AI: Build with LLMs

Estimating Cost

LLM pricing is quoted per million tokens. To budget a feature you convert a token count into dollars:

cost = (tokens / 1,000,000) Γ— pricePerMillion

Your task

Write costDollars(tokens, pricePerMillion) returning the cost in dollars, rounded to 4 decimal places.

⚑ 35 XP
solution.jsRuns in your browser
Loading editor…
Tests3 to pass
1M tokens at $3
500k at $10
zero tokens

Run your code to check these.