I'm trying to create a calculator program for my assignment course in JavaScript. The program has to calculate to numbers (values assigned by the user), as well as the operator (+, - , * ,/), and to display the result. If the user input an extra character in the field like (15n + 20 or 15 ++ 20 or 15+ + 20) has to display an error "Cannot concatenate a number with a string"
if the user divide a number by 0 has to display "Division by 0 is not allowed" Please I really need your help. I posted, my code bellow, let me know. What I'm doing wrong? I want to mention that I'm at the beginning level. Thanks, I appreciate all the advices
let numberOne = parseFloat(prompt("First Number: "));
let operator = prompt("Chose operation (+ - * /): ");
let numberTwo = parseFloat(prompt("Second Number: " ));
function DivisionByZero(a, b) {
if (a == 0 || b == 0 == true) {
throw "Divizion by 0 is not allowed";
}
}
function TypingError(a, b, c) {
if (numberOne + " " == true) {
throw "Cannot concatenate a number with a string";
} else if (numberTwo + " " == true) {
throw "Cannot concatenate a number with a string";
} else if (operator + operator == true) {
throw "Can not concatenate two operators"
}
}
let TypingErrorDisplay = TypingError(numberOne, operator, numberTwo);
var ErrorDivisionDisplay = DivisionByZero(numberOne, numberTwo);
if (operator === "+") {
var calc = parseFloat(numberOne) + parseFloat(numberTwo);
alert(calc);
}
else if (operator === "-") {
var calc = parseFloat(numberOne) - parseFloat(numberTwo);
alert(calc);
}
else if (operator === "*") {
var calc = parseFloat(numberOne) * parseFloat(numberTwo);
alert(calc);
}
else if (operator === "/") {
var calc = parseFloat(numberOne) / parseFloat(numberTwo);
alert(calc);
if (ErrorDivisionDisplay == true) {
alert("Division by 0 is not allowed");
}
}
else {
alert(TypingErrorDisplay);
}