arithmetic operation
Let's take a look at JavaScript arithmetic operation.
All addition, subtraction, and division of JavaScript must be performed as a function.
function sum (a,b){
return (a+b);
}//This is a function that means adding A and B.
function sub(a,b){
return (a-b);
}//It is a function that means taking B out of A.
function gob(a,b){
return (a*b);
}//This is a function that means multiplying A by B.
function divide(a,b){
return (a/b);
}//This is a function that means dividing A and B.
function nam(a,b){
return (a%b);
}//Find the remainder when you divide the left operand into the right operand.
Let's go further and create an input window.
I will make a prompt with a message to enter a number.
let a = prompt('Please enter a number.');
let b = prompt('Please enter a number.');
If you type in like this, you will see this input window.
Now, if you don't enter a number here, let's make the message window "nop!" appear.
This is simple: write code using the if and else statements.
if(isNaN(parseInt(a)) || isNaN(parseInt(b))){
alert('nop!')
}else{
console.log(sum(a,b));
console.log(sub(a,b));
console.log(gob(a,b));
console.log(divide(a,b));
console.log(nam(a,b));
}
In this way, if it is not the number of 'isNaN', the 'alert' window displays a warning window called 'nop!'
If you enter a number in the input window, the code is executed in 'else'.
This can be seen in the console window.
typed 1 in a. In b, we entered 2.
It can be confirmed that the calculation has been made in the console window according to 'else'.