Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<!DOCTYPE html><html><body style="padding:20px;font-family:Arial"><input id="a" type="number" value="10" style="width:60px"> ÷ <input id="b" type="number" value="0" style="width:60px"><button onclick="go()" style="padding:6px 14px;background:#6366f1;color:white;border:none;border-radius:4px;margin-left:8px;cursor:pointer">Divide</button><p id="o"></p><script>function go(){const a=+document.getElementById("a").value,b=+document.getElementById("b").value;try{if(b===0)throw new Error("Cannot divide by zero!");document.getElementById("o").innerHTML="Result: <strong>"+(a/b).toFixed(4)+"</strong>";}catch(e){document.getElementById("o").innerHTML="<span style='color:red'>"+e.message+"</span>";}}</script></body></html>
Result
Open