javacript function code example
Example 1: function javascript
var x = myFunction(4, 3);
function myFunction(a, b) {
return a * b;
}
Example 2: simple javascript function
function idk() {
alert('This is an alert!')
}
idk()
Example 3: javascript function
var num1;
var num2;
function newFunction(num1, num2){
return num1 * num2;
}
Example 4: js function
function myfunction() {
console.log("function");
};
myfunction()
function calculate(x, y, op) {
var answer;
if ( op = "add" ) {
answer = x + y;
};
else if ( op = "sub" ) {
answer = x - y;
};
else if ( op = "multi" ) {
answer = x * y;
};
else if ( op = "divide" ) {
answer = x / y;
};
else {
answer = "Error";
};
return answer;
};
console.log(calculate(15, 3, "divide"));