When designing a calculator, remember the following mathematical rule:
The number over which the manipulation is carried out is called - operated ;
The type of operation is called an operator , for example, "+" or "-" ;
The number that is being manipulated is called the operand ;
So, it is necessary to check the operator and if it is "/", check the operand to zero.
For example:
var operate = prompt('число',''); var operator = prompt('операция "+", "-","*","/" ',''); var operand = prompt('число',''); var result; switch (operator) { case "+": { result = +operate + +operand; document.write('Резултат' + result); } break; case "-": { result = +operate - +operand; document.write('Резултат' + result); } break; case "*": { result = +operate * +operand; document.write('Резултат' + result); } break; case "/": { if (operand == 0){ document.write('На ноль делить нельзя'); } else{ result = +operate / +operand; document.write('Резултат' + result); } } break; }