Agyan
adda
Run
Reset
Copy
JavaScript Tutorial › JS Numbers and Math › Dice roller
Back to tutorial
Code
Edit, then press Run or Ctrl+Enter
<button onclick="roll()">Roll the dice</button> <h2 id="dice">?</h2> <p id="info"></p> <script> function roll() { const n = Math.floor(Math.random() * 6) + 1; document.getElementById('dice').textContent = n; } document.getElementById('info').textContent = 'Price with GST: ₹' + (499 * 1.18).toFixed(2); </script>
Result