◇ Power · functions and edge cases
How long will the battery last?
Estimate a robot's runtime from battery capacity and load current, with a safety margin.
- Level 1 · Explorer
- 4 tests
- technically checked
Your task
Battery capacity is quoted in milliamp-hours (mAh). Only about 80 % is usable before the voltage sags too far, so a quick estimate is:
hours = capacity × 0.8 / load current
Write runtimeHours(capacityMah, loadMa). If the load is 0 mA, return Infinity (JavaScript has a value for that).
Hints (0 of 2 shown)
What gets checked
- runtimeHours(2000, 100) → 16
- runtimeHours(1200, 300) → ≈ 3.2 (± 1e-9)
Plus 2 hidden tests for edge cases. They run in the sandbox like the others; only the result is shown.
Tab indents · Esc then Tab leaves the editor · Ctrl/⌘ Enter runs · Ctrl/⌘ Shift Enter checks · Ctrl/⌘ / comments
Press Run to see what your program prints.
Your code runs only in this browser, inside an isolated sandbox with no network access, and stops after 3 s. Nothing you type is sent to Tactiverge; drafts and progress are saved in this browser only.