How to check the division by zero through isFinite?

<input type="button" value=" &#215; " onclick="calculator.answer.value += '*';checkLength(this);" function div(value) { calculator.answer.value += '/'; if (!isFinite(calculator.answer.value)) { alert("Divide by zero error"); } } 
  • What's the problem? Your code is not completely clear and understandable. - newman
  • I wrote a function but something is missing, or I didn’t understand the work of isFinite - Cergiy Krepkiy
  • one
    In your code, you check some string. And not the result of the operation. Make an alert(calculator.answer.value) for debugging before checking and see what goes into the isFinite function - newman
  • I realized what the problem is, then I need to get everything except "/" with regular expressions and check for zero? - Cergiy Krepkiy
  • The regular expressions here are from guns on sparrows. I do not fully understand your main task, but it seems to me that you better change the whole concept of your script .. - newman

1 answer 1

 var result = 10/0; alert(isFinite(result)); 

Displays false

 var result = 10/2; alert(isFinite(result)); 

Displays true