Agyan
adda
Run
Reset
Copy
JavaScript Tutorial › JS While Loop › Doubling until 1000
Back to tutorial
Code
Edit, then press Run or Ctrl+Enter
<pre id="out"></pre> <script> let amount = 1; let days = 0; let text = ''; while (amount < 1000) { amount *= 2; days++; text += `Day ${days}: ₹${amount}\n`; } text += `\nIt took ${days} days to cross ₹1000.`; document.getElementById('out').textContent = text; </script>
Result