function myfunction() {
console.log("function");
};
myfunction() //Should say "function" in the console.
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")); //Should say 5 in console.
//I hope I helped!
// Five examples of non-arrow function expressions
function (x) { return x + x + x }
function (s, n) { return s.length > n }
function (p, n, r, t) { return p * Math.pow(1 + (r / n), n * t) }
function () { return Math.random() * 100 }
function (x, y) {
let xSquared = x * x
let ySquared = y * y
return Math.sqrt(xSquared + ySquared)
}
var x = myFunction(10, 10); // Function is called, return value will end up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
function walkTree(node) {
if (node === null) {
return;
}
// do something with node
for (let i = 0; i < node.childNodes.length; i++) {
walkTree(node.childNodes[i]);
}
}